Question : Looping for result sets

I have a result sets returning variable rows. The question is how do I loop through. I have a snippet below but it is not quite right. I would be grateful if someone would help me here.

if ( ! $query->expectsResults() )
{
throw new LQMException("The invoice template expects at least one record to be returned");
}

// Check if there are results to display
if ( $dispatch->hasResultsToDisplay() ) {

$result      = $dispatch->getCurrentResultSet();
      
      // We want the data from the first row, ie, index 0
      $result->setRowIndex(0);
      $name = $result->field('name');
      $reference = $result->field('reference');

      $nextRow = 1;
      $j = 1;
      $n =1;
      WHILE (nextRow) {


            
            
            $idinvoice[$j]= $result->field('idinvoice');
            $invoice[$j] = $result->field('invoice');
            $amount[$j] = $result->field('amount');
            $idpayment[$j] = $result->field('idpayment');
            $cheque_no[$j] = $result->field('cheque_no');
            $pdatetime[$j] = $result->field('pdatetime');
            $username[$j] = $result->field('username');
            $n++;
      }            

Answer : Looping for result sets

hi,

 WHILE ($nextRow) {        
            $idinvoice[$j]= $result->field('idinvoice');
            $invoice[$j] = $result->field('invoice');
            $amount[$j] = $result->field('amount');
            $idpayment[$j] = $result->field('idpayment');
            $cheque_no[$j] = $result->field('cheque_no');
            $pdatetime[$j] = $result->field('pdatetime');
            $username[$j] = $result->field('username');
            $n++;
            $nextRow = $result->nextRow();  
      }            
Random Solutions  
 
programming4us programming4us