StumbleUpon  Del.icio.us  Facebook  Reddit  Add to diigo  


Follow - Monx007
Article Time Stamp: 04 February 2009, 23:20:38 GMT+7

PHP: How To Reuse Mysql Query



QUESTIONS
How to reuse mysql query result that has been fetched from php mysql_fetch_array()?

For example:
//query my query statement
$query = mysql_query ("SELECT * FROM sample_table");

// So at here using while loop to populate the query result
while ($result = mysql_fetch_array($query))
{
echo $result[0]; // for example to display only first column
}

When running the code as above, record would be displayed. However if I were to fetch again the data for example:

//query my query statement
$query = mysql_query ("SELECT * FROM sample_table");

// So at here using while loop to populate the query result
while ($result = mysql_fetch_array($query))
{
echo $result[0]; // for example to display only first column
}

//after the first while loop, i loop again and no record returned
while ($result1 = mysql_fetch_array($query))
{
echo $result1[0];
}


ANSWER
After the first fetch, you can use mssql_data_seek before the second fetch data

Code Example:
mysql_data_seek($query, 0)

The number 0 means it will reset to the first row of the record set

Article Source: Monx Digital Library

Copyrighted@ Monx Digital Library, otherwise stated
Use of our service is protected by our Terms of Use



 Back To Previous Page ...  



 

 

 

AQWorlds Nulgath Secret Walkthrough