View Full Version : DB info into a session

08-02-2006, 03:24 AM
I have a query like this:

$db->query("SELECT * from ".$db_prefix."users where username='".$username."' and password='".$pw."'")

And I have a bunch of columns in that table. What I want to do, is have it then put it into a session.

Something like:

$_SESSION['username'], $_SESSION['email'], $_SESSION['pw'] so on soforth but automatically. I know how to do it with an array, but I don't think you can do the same for sessions.

08-02-2006, 03:58 AM
$_SESSIONS is just a global array; you can assign associative keys to it all you want. I recommend a multi-level array for organization's sake.

$row = mysql_fetch_assoc($result);
for ($i = 0; $i < mysql_num_rows($result); $i++) {
$_SESSION['loginstuff'][$i] = $row[$i];

08-02-2006, 08:09 AM
$_SESSION['loginstuff'] is empty. The query works, and is sending and validating correctly. print_r shows nothing.

Wouldn't that only do 1 column though, and then rotate through the rows? It should be doing all of the columns.

08-02-2006, 08:15 AM
would this work?

while($row = mysql_fetch_array($result)){
$table = mysql_query("SHOW COLUMNS FROM sometable");
while ($fields = mysql_fetch_array($table)) {
$_SESSION[$fields['Field']] = $row[$fields['Field']];

08-02-2006, 09:12 AM
or just:


(and that's probably one line too many...)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum