PDA

View Full Version : Transfer mysql_query result from one variable to another



sdlynx
October 26th, 2009, 01:04 AM
Hello,

I have:


$result = mysql_query("SELECT * FROM stories ORDER BY RAND() LIMIT 1", $con);


And I need to get another variable $result2 which is the same as $result. I have tried just $result2 = $result but it did not work, mysql_num_rows($result2) found the right number of rows but when I tried to while($row = mysql_fetch_array($result2)) it didn't loop even once. Does anyone know how to properly get $result2 to equal $result?

SDLynx

P.S. This is PHP and MySQL.

januzi
October 26th, 2009, 01:39 AM
Try:


mysql_data_seek($result2, 0);

sdlynx
October 26th, 2009, 01:51 AM
Try:



in place for what?

januzi
October 26th, 2009, 01:54 AM
Put it before while( $row = ...

sdlynx
October 26th, 2009, 03:10 AM
Put it before while( $row = ...

wow, it worked! thanks!