The right method (in my opinion) to check whether the mysql_fetch_array is empty is to count the number of rows :-
Example :Â $tenant_query=mysql_query(”SELECT t.*, c.* FROM tenant t, category c WHERE t.category__id=c.category_id ORDER BY category_name ASC”) or die(mysql_error());
After the query, we shall
<?php if(mysql_num_rows($tenant_query) == 0) {  ?>
 <tr><td colspan=”4″>There is no tenant in this category</td></tr>
 <?php } ?>
As you can see, we use mysql_num_rows to check. If mysql_num_rows returns 0, means there is no record from the query.
If there is record, then we will fetch array from the query,
<?php while($tenant=mysql_fetch_array($tenant_query)) {Â ?>
That’s all, continue the rest of the coding on what you have to do!
January 10th, 2009
Tags: MySQL



Home