PHP ADODB - Reuse Query Result?

94 views Asked by At

How does one reuse a query result with PHP ADODB, at the moment I am doing this, which I assume is inefficient? :

$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();                                                                    
   }
1

There are 1 answers

1
BishBoshBash On

To answer my own question, need to use:

$result1->move(0);

so like this:

$query = "SELECT colname FROM table";
$result1 = $db->SelectLimit($query,10,-1);

// 1ST RUN
while (!$result1->EOF) { 
 echo $result1->Fields('colname').'<br>';
 $result1->MoveNext();   
}
// 2ND RUN
$result1->move(0); // move recordset cursor back to 0
while (!$result1->EOF) { 
 echo $result1->Fields('colname').'<br>';       
 $result2->MoveNext();                                                                    
}