variable variables and Sessions
| From: | Anup | Date: | Wed, 31 Jul 2002 04:47:51 +0000 |
| Subject: | variable variables and Sessions | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-110457@lists.php.net to get a copy of this message | ||
I have a question about the following
$LoadResult = mysql_query("SELECT * from Items where username='test' and
password='test'");
$num_results =mysql_num_rows($LoadResult);
for ($i=0; $i < $num_results;$i++) {
$myrow = mysql_fetch_array($LoadResult, MYSQL_ASSOC);
$ProductName = $myrow["ProductName"];
$Quantity = $myrow["Quantity"];
$$ProductName = $Quantity; [1]
$HTTP_SESSION_VARS[$ProductName] = $Quantity; [2]
session_register("$ProductName"); [3]
}
/*END CODE*/
so what I want to do is through the query result, create new session
varaibles, where the name of the variable is $ProductName and whose value is
$Quantity.
for some reason if I just have lines [2] and [3] then the session variables
are present, but once the page is reloaded/refreshed they are gone. However
if I have lines [1] and [3], then my code can't access the session variables
(through calls to $HTTP_SEESION_VARS) until the page is refreshed. It seems
odd that I have to write lines [1] AND [2] to make the code work. They seem
symantically correct.
Thanks in Advance,
Anup