Re: SESSION array problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



tedd wrote:
> At 2:43 PM -0500 10/1/08, Afan Pasalic wrote:
>> just tested. works fine
>>
>>
>>
>> $_SESSION = array(
>>     '6156' => array(
>>                                 'first_name'    => 'Diane',
>>                                 'last_name'     => 'Cable'),
>>     '7030' => array(
>>                         'first_name'    => 'Fred',
>>                         'last_name'     => 'Cago'),
>>     '656' => array(
>>                         'first_name'    => 'Helen',
>>                         'last_name'     => 'Cahalan')
>>     );
>>
>> echo '<pre>';
>> print_r($_SESSION);
>>
>> foreach ($_SESSION as $key => $value)
>> {
>>     echo $_SESSION[$key]['last_name'].',
>> '.$_SESSION[$key]['first_name'].'<br>';
>> }
>>
>> -afan
>
> -afan:
>
> That's fine, but that's not the problem.
>
> The problem is:
>
>  $_SESSION['user_id'][] = '6156';
>  $_SESSION['first_name'][]  = 'Diane';
>  $_SESSION['last_name'][]    = 'Cable';
>
>  $_SESSION['user_id'][] = '1234';
>  $_SESSION['first_name'][]  = 'Big';
>  $_SESSION['last_name'][]    = 'Ron';
>
>  $_SESSION['user_id'][] = '8867';
>  $_SESSION['first_name'][]  = 'Joe';
>  $_SESSION['last_name'][]    = 'Dirt';
>
> Now, how do you retrieve it?
>
> Cheers,
>
> tedd
>

tedd,
I just copied your code, created your sessions and - it works fine.
http://afan.net/tedd.php

code:
<?php
session_start();

$_SESSION['user_id'] = array(6156, 7030, 656);
$_SESSION['first_name'] = array('Diane', 'Fred', 'Helen');
$_SESSION['last_name'] = array('Cable', 'Cago', 'Cahalan');

echo '<pre>';
print_r($_SESSION);

$num_users = count($_SESSION['user_id']);  // <--- this works (correct
$num_users)
echo "?: ".$num_users.'<br><table border="1">';

for ($i = 0; $i < $num_users; $i++)
{
   $last_name = $_SESSION['last_name'][$i];
   $first_name = $_SESSION['first_name'][$i];
   echo("<tr><td>$last_name</td><td>$first_name</td></tr>");
}

echo '</table>';


I think there is something outside your code.

-afan



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux