Hi, I'm Ahmad. I make websites with Joomla!

Welcome, Feel free to navigate my website and I will be glad to hear from you.

Download Calendar Stamp 1.5

Recommended Book

0523_Mastering_Joomla_1

What's going on twitter

  • I took it and so should you—The Survey for People Who Make Websites 2011! http://t.co/xG9Gv0i5 via @alistapart
  • why doesn't #facebook push #html5 notifications instead of #javascript ? seriously?
  • Any one knows where to get one of those standing desks in Egypt? http://t.co/e1Enk4bX
07
Aug
2009
Counting rows from MySQL database using PHP/SQL PDF Print E-mail

DatabaseThere are two ways to retrieve the number of rows selected from a database; either by using the PHP function mysql_num_rows() or by using the SQL COUNT() Function. Take a look at the following :

  1. Using PHP
        $query = "SELECT (column) FROM table WHERE column = value";
        $results = mysql_query($query);
        $rows = mysql_num_rows($results); 
        echo $rows ;
  2. Using SQL
       $query = "SELECT COUNT(column) FROM table WHERE column value";
       $results = mysql_query($query);
       $rows = mysql_fetch_array($results);
       echo $rows[0];

Both will get the same results, experiments and discussions revealed that using SQL COUNT() function is much faster as it doesn't use much resources as the first method. Also using COUNT(*) is faster than using COUNT(column) because when you specify a certain field; MySQL has to open each row and look around for that field.