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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.