telsiin Posted September 26, 2008 Share Posted September 26, 2008 I was wondering if it possiable to create a Dynamic Session variable base on the result of a query from MYSQl something where I would first run a query mysql_select_db($database_looptakeout, $gatekeeper); $query_menu = "SELECT * FROM storeitems WHERE storeitems.manufactureID='$_SESSION[manuname]' order by category ASC,item_name desc"; $menu = mysql_query($query_menu, $gatekeeper) or die(mysql_error()); $row_menu = mysql_fetch_assoc($menu); $totalRows_menu = mysql_num_rows($menu); then use the result of the query to create the session variable. I would then set the value of the session on a different page $_SESSION{echo $row_menu['item_name']}; OR $_SESSION{$row_menu['item_name']}; Thank very much for you help Link to comment https://forums.phpfreaks.com/topic/125875-dynamic-session-variable-base-off-querys/ Share on other sites More sharing options...
redarrow Posted September 26, 2008 Share Posted September 26, 2008 what u mean....... <?php session_start(); //database conection mysql_select_db($database_looptakeout, $gatekeeper); $query_menu = "SELECT * FROM storeitems WHERE storeitems.manufactureID=' ".$_SESSION['manuname']."' order by category ASC,item_name desc"; $menu = mysql_query($query_menu, $gatekeeper) or die(mysql_error()); while($row_menu=mysql_fetch_assoc($menu)){ $_SESSION['row_menu']=$row_menu['field_name']; //echo $_SESSION['row_menu']; } ?> Link to comment https://forums.phpfreaks.com/topic/125875-dynamic-session-variable-base-off-querys/#findComment-650915 Share on other sites More sharing options...
telsiin Posted September 26, 2008 Author Share Posted September 26, 2008 No I don't think that would work for me because then the SESSION variable would be $_SESSION['row_menu']with the value of $row_menu['field_name']; but that would only be one variable what I am try to do is create multple "unique" session variable each time the result of $row_menu['field_name']; is different some more like an example from http://www.jauhari.net/dynamic-variables-in-php.jsp $var = "hello"; Now let’s say you want a variable whose name is the value of the $var variable. You can do that like this: $$var = "World"; PHP parses $$var by first dereferencing the innermost variable, meaning that $var becomes “hello”. The expression that’s left is $”hello”, which is just $hello. In other words, we have just created a new variable named hello and assigned it the value “World”. You can nest dynamic variables to an infinite level in PHP, although once you get beyond two levels, it can be very confusing for someone who is trying to read your code. however what need is the syntax to apply the above to a $_SESSION and have the value from my query become a new varible if its possiable Link to comment https://forums.phpfreaks.com/topic/125875-dynamic-session-variable-base-off-querys/#findComment-651017 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.