Posted By

brownrl on 06/27/11


Tagged

database records tables total


Versions (?)

PHP getTotal


 / Published in: PHP
 

URL: http://www.itsgotto.be/cv.php

Simple function to return the total records in a DB. This function probably has to be modified for every project you do to adjust for your db layer and server. I have it here simply because I use ado-db lite and my other functions almost all the time.

  1. <?php
  2.  
  3.  
  4. // Function Get Total Records
  5. //
  6. // Get the total records from a db table
  7. //
  8. // $table -> the table to check
  9. // $where -> optional WHERE clause
  10. //
  11.  
  12. function getTotal( $table , $where = "" )
  13. {
  14. $q = "SELECT COUNT( * ) as total FROM `".mysql_escape_string( $table )."` ".$where;
  15. $qr = dbquery( $q ); // your db query probably differs I use ado db lite wrapper.
  16. return $qr->fields['total'];
  17. }
  18.  
  19. ?>

Report this snippet  

You need to login to post a comment.