Page 1 of 1

MYSQL result resource and sessions

Posted: Wed Sep 22, 2010 1:54 pm
by spacebiscuit
Hi,

Can anyone tell me why a MYSQL result resource cannot be stored in a session value. For example:

Code: Select all

 if(isset($_GET[x])){	  
      $query="SELECT comments FROM table1";
      $_SESSION[comments]=mysql_query($query);
                            }

 $comment=mysql_result($_SESSION[comments],0);
When $_GET[x] is set $_SESSION[comment] is loaded as expected with the results of the query - there are around 50 rows returned. I can then access the rows of the result one at a time.

However if the script is accessed a second time and $_GET[x] is not set the session seems to have failed becauase I get a message that I am using an invalid mysql resource. I know I could use mysql_fetch_row but I am trying to keep the code more efficient by only calling the query once when the script is first read.

Sessions are working elsewhere on the page so it is nothing obvious. It just seems not possible to store the result in a session.

Any ideas?

Thanks,

Rob.