Re: [PHP] SESSION array problems
- From: afan@xxxxxxxx (Afan Pasalic)
- Date: Wed, 01 Oct 2008 14:38:11 -0500
tedd wrote:
Hi gang:
Apparently, there's something going on here that I don't understand --
this happens far too often these days.
Here's a print_r($_SESSION); of the session arrays I'm using:
[user_id] => Array
(
[0] => 6156
[1] => 7030
[2] => 656
)
[first_name] => Array
(
[0] => Diane
[1] => Fred
[2] => Helen
)
[last_name] => Array
(
[0] => Cable
[1] => Cago
[2] => Cahalan
The following is how I tried to access the data contained in the
$_SESSION arrays:
$num_users = count($_SESSION['user_id']);
for ($i = 0; $i < $num_users; $i++)
{
$last_name = $_SESSION['last_name'][$i];
$first_name = $_SESSION['first_name'][$i];
echo("<p>$last_name, $first_name</p>");
}
The only thing that came out correct was the first echo. The remaining
echos had no values for $first_name or $last_name.
What's happening here?
Cheers,
tedd
PS: I'm open to other suggestions as to how to do this.
hi tedd,
if I may suggest this "model"
$_SESSION
{
[6156]
{
[first_name] => Diane
[last_name] => Cable
}
[7030]
{
[first_name] => Fred
[last_name] => Cago
}
[656]
{
[first_name] => Helen
[last_name] => Cahalan
}
}
main reason - if you sort by first or last name you will lose "index".
this way is index always "linked" to first/last name.
foreach ($_SESSION as $key => $value)
{
echo $_SESSION[$key]['last_name'].',
'.$_SESSION[$key]['first_name'].'<br>';
}
didn't test it, though :-)
-afan
.
- Follow-Ups:
- Re: [PHP] SESSION array problems
- From: tedd
- Re: [PHP] SESSION array problems
- References:
- SESSION array problems
- From: tedd
- SESSION array problems
- Prev by Date: Re: [PHP] Re: problem with slash / characters
- Next by Date: [PHP] Re: SESSION array problems
- Previous by thread: Re: [PHP] Re: SESSION array problems
- Next by thread: Re: [PHP] SESSION array problems
- Index(es):
Relevant Pages
|