Jump to content

Session variables sending specific variable from a while loop


sexyweb

Recommended Posts

I have this simple while loop which retrieves data from a mysql query and displays several links on my homepage.

 

I would like to avoid using the php get function and add query strings to my urls

 

I am thinking of using session variables but I need help and I'm pretty sure this can't be done.

 

When a visitor clicks a link from the several ones displayed by the while loop, that particular variable would be set in a session.

 

In my code, the session will always send the last var :(

 

Can this be done?

 

   

<? session_start(); // Start Session Variables

    $result = mysql_query("my query");

    while($slice = mysql_fetch_assoc($result)){
        $url = $slice['url'];
        $name  = $slice['name']; ?>

        <a href="<? echo $url; ?>"><? echo $name; ?></a>

    <? } 

    $_SESSION['name'] = $name; // Store session data  ?>

not quite sure what you mean

 

but in your code $_SESSION['name']=$name will always give you the last value of $name because it is only one variable.

 

if you want to store more than one $name in $_SESSION you will have to have either different indexes or store them all in one $_SESSION['name'] ="Joe|Andy|Bert|etc" and then explode them on a vertical bar to an array later. Maybe I have not understood what you want.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.