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

Bob Patin bob at patin.com
Fri Sep 17 07:42:33 MDT 2010


Right, I know those 2 are different, but that part seems to work; it populates my database just fine.

And when I put this at the bottom of the first loop, I do see values in my arrays:

		echo $_SESSION['recid['.$recid.']']."   ".$_SESSION['description['.$recid.']'];

It's this loop that doesn't seem to be correct:

  <?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
}
?>

Should my FOREACH() be different?

Thanks,

Bob



On Sep 17, 2010, at 8:26 AM, Leo R. Lundgren wrote:

> 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.
> 
> 



More information about the FX.php_List mailing list