Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My code is like below:
(Assuming database connection is established and required database is selected)
Note: queryFire($query) is a user defined function in some file.


PHP
/* some lines of code here */
     $result = $db->queryFire("select * from ssubcategory;");
     if($result){
        while($row=mysql_fetch_array($result)){
             echo $row[0];

     /* some lines of code here */
     while($newrow=mysql_fetch_array($result))
        echo $row[0];



In the first while loop all data is retrieved and is successfully displayed in browser.
But, when it comes to last while loop, I get no data displayed in the browser with the same array variable $result.
Let me know, if the database array $result go blank after first fetch or there is some other conceptual thing I am unaware of.
Posted

1 solution

In the second fetch the array is already fetched so the 'cursor' is in the end of the result set. In order to fetch the same array again, you need to go to the beginning.

Try adding
PHP
if (!mysql_data_seek($result, 0)) {
    echo "Seek failed: " . mysql_error();
}

after the first fetch.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900