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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts

    extract() advice required

    Okay... I am just going to post the code I have used. It doesn't work but I am sure you will all see what I am trying to do - I assume I sort of have it backwards.

    PHP Code:
    $result mysql_db_query(ysl"SELECT * FROM users WHERE id='$uid'");
    $row mysql_fetch_array($result);
    $_SESSION["extract($row)"];
    echo 
    "$_SESSION[uid]"
    No errors come up - but the session uid does not set.

    Any help appreciated.

    Thanks in advance!

    Taylor.

  • #2
    Regular Coder
    Join Date
    May 2004
    Location
    sweden
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is session_start() at the top ofthe page?
    Carl McDade
    _____________
    Hiveminds Magazine
    for web publisher and community builders
    eRuby Tutorials

  • #3
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    My session_start() does not need to be on - global_register is on. However thats not the issue. It's the $_SESSION[extract($row)]. Basically I am trying to save myself from doing this:

    PHP Code:
    extract($row);
    $_SESSION[username] = $username;
    $_SESSION[email] = $email;
    $_SESSION[yaps] = $yaps
    // etc etc etc etc 
    Taylor.

  • #4
    Regular Coder
    Join Date
    May 2004
    Location
    sweden
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Have you tried it without the quotes? or How about

    Code:
    <?php
    
    $size = "large"; 
    $mySQLdata = array("color" => "blue", 
                      "size"  => "medium", 
                      "shape" => "sphere"); 
    
    
    foreach ($mySQLdata as $a=>$b){
    $_SESSION[$a] = $b;
     }
    
    foreach ($_SESSION as $c=>$d){
    print $c . "=";
    print($d) . "<br>";
     }
    ?>
    Last edited by carl_mcdade; 06-04-2004 at 07:35 PM.
    Carl McDade
    _____________
    Hiveminds Magazine
    for web publisher and community builders
    eRuby Tutorials

  • #5
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    Yep I have tried it without the quotes, and no the while() cannot be used because that would be asking for it to extract whenever id=uid - which is only once.

  • #6
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    Found the answer:

    PHP Code:
    $result mysql_db_query(ysl"SELECT * FROM users WHERE id='$uid'");
    $row mysql_fetch_array($result);
    function 
    xtract($a,$prefix) {
           foreach(
    $a as $key=>$val$_SESSION["$prefix_{$key}"]=$val;
       }

    xtract($row"l");

    echo 
    "$_SESSION[l_username]";
    echo 
    "$_SESSION[l_email]"

  • #7
    Regular Coder
    Join Date
    May 2004
    Location
    sweden
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, you found that while I was stinking out my own code. If you check the above again you'll we came to the same solution
    Carl McDade
    _____________
    Hiveminds Magazine
    for web publisher and community builders
    eRuby Tutorials

  • #8
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    well you can simply either ...

    PHP Code:
    <?
    $_SESSION 
    array_merge$_SESSION $row  ) ;
    ?>
    or even 
    <?
    $_SESSION 
    += $row ;
    ?>
    though the end solution you ended up with is probably better as it lets you decide whether to overwrite existing array keys and/or prefix them.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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