Re: SESSION array problems

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

 



Nathan Rixham wrote:
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.

ehh? i think everybody's looking too hard at this..

[tested - works]
<?php

 $_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';

 print_r( $_SESSION );

 foreach( $_SESSION['user_id'] as $index => $value ) {
   $last_name = $_SESSION['last_name'][$index];
   $first_name = $_SESSION['first_name'][$index];
   echo $last_name . ',' . $first_name . PHP_EOL;
 }
?>

regards! nathan :)


I need to re-address this.. tedd your original code works fine over here; as does the code I sent you, and the code jay submitted first..

do us a favour, copy and paste exactly what I just handed through and run it; are the results correct?

next up, is you're real code somewhat bulkier and more too it? if so then something runs in my head that you should check if you already have a $last_name / $first_name somewhere earlier, and if you do where they passed by reference to the function that produced the array in session? of so then you could be redefining the session data at the same time as retrieving it or something completely crazy.

actually I think your php install is bustikated!

Nath

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