Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    DB info into a session

    I have a query like this:

    PHP Code:
    $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.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    $_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.

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


  • #3
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    $_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.

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    would this work?
    PHP Code:
    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']];
        }


  • #5
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    or just:
    PHP Code:
    $array=mysql_fetch_assoc($rs);
    $_SESSION['loginstuff']=$array
    (and that's probably one line too many...)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •