[FX.php List] Trying to read back an array

Leo R. Lundgren leo at finalresort.org
Fri Sep 17 08:23:50 MDT 2010


17 sep 2010 kl. 16.08 skrev Bob Patin:

> So, one last couple of questions, and then I'll quit bothering you:
> 
> To store these 5 vars into a single array, I have this:
> 
> $_SESSION['recid']['description'] = $_POST['description'.$recid] ;
> $_SESSION['recid']['type'] = $_POST['type'.$recid] ;
> $_SESSION['recid']['serial'] = $_POST['serial'.$recid] ;
> $_SESSION['recid']['problem'] = $_POST['problem'.$recid] ;
> $_SESSION['recid']['recid']] = $recid ;

Assuming there are multiple recids and you want to store them all in the session, you must store them in seperate places:

	$_SESSION[$recid]['description'] = $_POST['description'.$recid] ;
	$_SESSION[$recid]['type'] = $_POST['type'.$recid] ;
	$_SESSION[$recid]['serial'] = $_POST['serial'.$recid] ;
	$_SESSION[$recid]['problem'] = $_POST['problem'.$recid] ;
	$_SESSION[$recid]['recid'] = $recid ;

> I'm questioning the last line... is that right? Seems wrong...

The last line (in the code I pasted above) isn't necessary since you already know the recid from the first level of keys in the array. For example when you loop:

	foreach($_SESSION as $id => $record) {
		// Here $id is the recid, and $record is an array containing the description and type and so on, each in their corresponding key.
	}

Note that if you want to store other data than records in the session, you should probably put all the above inside a "main" element in the session array, such as:

	$_SESSION['hereAreMyRecords'][$recid]['description']
	$_SESSION['hereAreMyRecords'][$recid]['type']
	...

That way you can foreach($_SESSION['hereAreMyRecords'] ..) instead of the entire $_SESSION, and thereby store other information in the session at for example $_SESSION['andSomeOtherData'].


> Thanks,
> 
> BP
> 
> 
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list



-|



More information about the FX.php_List mailing list