mcfc4heatons Posted April 30, 2022 Share Posted April 30, 2022 I'm working on a PHP ADODB Project and want to reuse a query result and loop through results again, at the moment I am using the following approach, but assume this is inefficient and there must be a better approach?: $query = "SELECT colname FROM table"; $result1 = $db->SelectLimit($query,10,-1); $result2 = $db->SelectLimit($query,10,-1); // 1ST RUN while (!$result1->EOF) { echo $result1->Fields('colname').'<br>'; $result1->MoveNext(); } // 2ND RUN while (!$result2->EOF) { echo $result2->Fields('colname').'<br>'; $result2->MoveNext(); } Quote Link to comment https://forums.phpfreaks.com/topic/314741-php-adodb-reuse-query-result/ Share on other sites More sharing options...
kicken Posted April 30, 2022 Share Posted April 30, 2022 You could just read the results into an array, then use that for your two loops. $query = "SELECT colname FROM table"; $result1 = $db->SelectLimit($query,10,-1); $resultData=[]; while (!$result1->EOF) { $resultData[]=$result1->Fields('colname'); $result1->MoveNext(); } // 1ST RUN foreach ($resultData as $colname){ echo $colname.'<br>'; } // 2ND RUN foreach ($resultData as $colname){ echo $colname.'<br>'; } Quote Link to comment https://forums.phpfreaks.com/topic/314741-php-adodb-reuse-query-result/#findComment-1595809 Share on other sites More sharing options...
Barand Posted April 30, 2022 Share Posted April 30, 2022 mysqli has a fetch_all() method and PDO has a fetchAll() method. Both of the above would create that array for you. Does ADODB have the equivalent? Quote Link to comment https://forums.phpfreaks.com/topic/314741-php-adodb-reuse-query-result/#findComment-1595811 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.