Say you have a table with 28 fields, and you want to assign each array value to a session, can this be done?
The following peace of code gets all the array values for a given tables search:
$sql = (SELECT * FROM accounts where username='lordmerlin');
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){ $$key = stripslashes( $val );
}
echo $username;
So, if you have say normally type in echo $sql[username];, you now only need to type in echo $username;
But, can those variables be asigned to sessions?
I tried this, but it doesn't work 🙂
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){ $$key = stripslashes( $val );
$_SESSION[$$key] = $$key;
}
echo '<pre>';
print_r($$key);
print_r($_SESSION);
echo '</pre>';
If you run the last piece of code, you'll see it creates the session variables from the array variables, but they are empty. print_r($$key) however does print out the array values.😕