Datasets Don't Do that! Why?

Discussion in 'PHP' started by prabha_friend, Jun 29, 2009.

  1. #1
    index.php
    <?php
    $_SESSION['Set'] = mysql_query("Select * from SOMETABLE");
    $_SESSION['Test']=“Testval“;
    redirect('Dummy.php');
    ?>
    Dummy.php
    <?php
    echo $_SESSION['Test'];
    $myrow = mysql_fetch_array($_SESSION['Set']);
    echo $myrow['USERID'];
    ?>
    Why Dont I get the results from a Session's Dataset variable like any other Session's variables. How to pass datasets from page to page. Work on stake. Help needed. Thanks in advance.
     
    prabha_friend, Jun 29, 2009 IP
  2. Louis11

    Louis11 Active Member

    Messages:
    783
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #2
    Why on earth would you want to do that? Why not just pull up the necessary data on the respective pages?
     
    Louis11, Jun 29, 2009 IP
  3. prabha_friend

    prabha_friend Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hello friend. Thanks for your reply. I did that through other way. Still, I want to know that it is possible to store a dataset as session variable. Just a curiosity. Thanks in Advance.
     
    prabha_friend, Jun 29, 2009 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    Yes it is possible. The best way would be to cast it to an array.

    $_SESSION['Set'] = mysql_query("Select * from SOMETABLE");

    will not work, because mysql_query returns a resource and not a string or actual data.

    You would need to loop through the data, put it all into an array, serialize it, and store it as a session variable for it to work properly.
     
    jestep, Jun 29, 2009 IP
  5. Goramba

    Goramba Peon

    Messages:
    128
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Is this what you're looking for?


    $result = mysql_query($_SESSION['Set']);
    while($row = mysql_fetch_array($result))
    {
    $USERID[]=$row['USERID'];
    }
    $uid= implode(",", $USERID);
    echo $uid;
     
    Goramba, Jun 29, 2009 IP
  6. Louis11

    Louis11 Active Member

    Messages:
    783
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #6
    Yes it is possible, serialize the data.

    
    $_SESSION['data'] = serialize(mysql_query(" . . . "));
    
    PHP:
    And on the page you want to access the data:

    
    $mysql_resource = unserialize($_SESSION['data']);
    
    PHP:
     
    Louis11, Jun 29, 2009 IP