MYSQL result resource and sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

MYSQL result resource and sessions

Post 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.
Post Reply