fulldecent/thin-pdo

How to print SELECT query results?

GoogleCodeExporter opened this issue · 1 comments

All questions concern the SELECT queries:

1. How to make a rowcount on a table and echo the number of rows?

2. How to use a while loop to go through some query results and display them?

Thanks
Stefan

Original issue reported on code.google.com by schneide...@gmail.com on 8 Feb 2013 at 4:11

There are couple of ways to take care of your questions but I'll answer them 
using just the $db->select() function.

1. To echo the row count on a select could be done as follows:
     $aResults = $db->select('mytable');
     echo count($aResults);

2. To loop through the query results the following could be used:
     $aResults = $db->select('mytable');  //$db->run($customSql) could be used here too.
     foreach($aResults as $aResultRecord) {
          print_r($aResultRecord);
     }

Hopefully that helps!

Original comment by ayd...@gmail.com on 18 Jun 2014 at 2:02

  • Changed state: Done
  • Added labels: Type-Task
  • Removed labels: Type-Defect