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

Leo R. Lundgren leo at finalresort.org
Fri Sep 17 07:47:06 MDT 2010


That's exactly what I am trying to point out.

You store using this key in the array:

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

The key in the array will be "description[123]" for a recid of 123.

You then try to fetch it using this:

	$_SESSION['description'.$recid]

Which is the equivalent of a key "description123" for a recid of 123.

So you are asking for the value in the array at place (key) foo, when having stored it at place (as key) bar. Or the reverse :)


17 sep 2010 kl. 15.42 skrev Bob Patin:

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