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

Leo R. Lundgren leo at finalresort.org
Fri Sep 17 07:26:05 MDT 2010


You are setting this:

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

And then trying to fetch it like this:

	$_SESSION['description'.$recid]

Those two expressions are not the same, so you don't get any data back.

Have you looked at your PHP error log (with Apache this is by default the error_log file)? There's probably a ton of errors in there :)

The part:

	if( (strlen($_POST['recid'])>0) && (is_array($_POST['recid']))) {

is better off like:

	if( isset($_POST['recid']) && is_array($_POST['recid']) ) {

No need for those extra () (but they don't hurt!), and first checking if the *string* length of a variable is > 0, and then checking if the variable is an *array* doesn't add up.
I'm guessing you want to see that the variable is set and that it is an array, that's what the code above does :)
The thing is that apart from the "double" type comparison, you'd get a bunch of warnings in the error log if $_POST['recid'] isn't set.


17 sep 2010 kl. 15.18 skrev Bob Patin:

> Hi guys,
> 
> In my last episode our hero was trying to store input into arrays; he got that far...
> 
> Now he's trying to get this back, and here's the problem:
> 
> I store the POST values here:
> 
> // loop through the recid array and create the product arrays
> if( (strlen($_POST['recid'])>0) && (is_array($_POST['recid']))) {
> 	foreach($_POST['recid'] as $recid) {
> 		$_SESSION['description['.$recid.']'] = $_POST['description'.$recid] ;
> 		$_SESSION['type['.$recid.']'] = $_POST['type'.$recid] ;
> 		$_SESSION['serial['.$recid.']'] = $_POST['serial'.$recid] ;
> 		$_SESSION['problem['.$recid.']'] = $_POST['problem'.$recid] ;
> 		$_SESSION['recid['.$recid.']'] = $recid ;
> 	}
> }
> 
> I can return $recid with no trouble, so I'm fairly certain that all my session vars are getting populated.
> 
> NOW... I want to show these on the same page, and wrote this:
> 
> 	  <?php
> 	  // loop through the recid array and create requests for each item
> 		foreach($_SESSION['recid'] as $recid) {
> 			$status = "Open; pending manufacturer approval";
> 			$description = $_SESSION['description'.$recid];
> 			$problem = $_SESSION['problem'.$recid];
> 			$serial = $_SESSION['serial'.$recid];
> 			echo $recid;
> 	?>
> <<<< TABLE >>>>
> <?php
> }
> ?>
> 
> What am I missing here? My FOREACH doesn't return anything at all, and doesn't loop a single time.
> 
> Thanks,
> 
> 
> Bob Patin
> Longterm Solutions
> bob at longtermsolutions.com
> 615-333-6858
> http://www.longtermsolutions.com
> iChat: bobpatin
> FileMaker 9, 10 & 11 Certified Developer
> Member of FileMaker Business Alliance and FileMaker TechNet
> --
> Expert FileMaker Consulting 
> FileMaker Hosting for all versions of FileMaker
> PHP • Full email services • Free DNS hosting • Colocation • Consulting
> 
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list



-|

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.iviking.org/pipermail/fx.php_list/attachments/20100917/f8a7b02e/attachment.html


More information about the FX.php_List mailing list