sexyweb Posted December 23, 2011 Share Posted December 23, 2011 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/253746-session-variables-sending-specific-variable-from-a-while-loop/ Share on other sites More sharing options...
ocpaul20 Posted December 26, 2011 Share Posted December 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253746-session-variables-sending-specific-variable-from-a-while-loop/#findComment-1301305 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.