Tuesday, November 5, 2013

How to use the same MySQL query again and again

Actually, what we going to do is to move the internal row pointer to re-query. For this, Im going to use the mysql function mysql_data_seek().


The internal row pointer is the current row position in a result returned by the mysql_query() function.

$sql    = "SELECT * FROM tbl_data";
$result = mysql_query($sql,$con);

while ($row = mysql_fetch_array($result)) {
   /* Show your data here*/
}

/* Call the result info again*/

mysql_data_seek($result,0); 

//  you can change the 0 into any number. From this, it will control from which row number you want to start the query again.

while ($row = mysql_fetch_array($result)) {
   /* Show your data for the 2nd time */
}

No comments:

Post a Comment