Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I need to loop over $result more than once, yet I can only call sqlsrv_fetch_array($result) once. If I try to use it again in the script, I get nothing. Here is an example:

PHP
$result = sqlsrv_query($conn,$query,$sql_params,SQLSRV_CURSOR_FORWARD);


PHP
while ($row = sqlsrv_fetch_array($result)) {
   while ($arow = sqlsrv_fetch_array ($aresult)) {
        echo $arow[foo];
   }
}


I used sqlsrv_fetch($aresult, SQLSRV_SCROLL_FIRST) to set cursor, but don't right. If I try $query is SELECT query, it's OK.

What are you supposed to do when you need to loop over your database query results multiple times ?
Posted
Comments
Mohibur Rashid 20-Jan-14 2:26am    
first loop through once and store them all in a temporary data. then do your process

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