0

What would I need to add so that I can return a count of the number of rows retrieved in the query? I am not sure where to include the COUNT (another query?) and then what syntax to use to print the result. thanks

$data = mysql_query('SELECT * FROM `bus_basic` ORDER BY `name` ASC ')
or die(mysql_error());

Print "<table cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "".$info['name'] . " ";
Print "<br>&nbsp;&nbsp;&nbsp;".$info['address'] . " ";
Print "<br>&nbsp;&nbsp;&nbsp;".$info['city'] . ", ";
Print "".$info['state'] . "&nbsp;&nbsp;";
Print "".$info['zip'] . " ";
Print "<br>&nbsp;&nbsp;&nbsp;".$info['phone'] . " ";
Print "<br><b>Main Category:</b> ".$info['cat1'] . " ";
Print "<br>&nbsp;&nbsp;&nbsp;<b>Sub Category:</b> ".$info['subcat1'] . " ";
Print "<br>&nbsp;&nbsp;&nbsp;<b>Sub Category:</b> ".$info['subcat2'] . " <br><hr> </td></tr>";
}
Print "</table>";
3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by Suomedia
0

Oh, some details:
server is running php4
mysql version 5
I use dreamweaver and phpmyadmin.

i hope that helps

0

A common way to do it is this:

$data = mysql_query('SELECT * FROM `bus_basic` ORDER BY `name` ASC ')
or die(mysql_error());

Print "<table cellpadding=3>";
$count = 0;
while($info = mysql_fetch_array( $data ))
{
$count++;
Print "<tr>";
Print "".$info['name'] . " ";
Print "<br>&nbsp;&nbsp;&nbsp;".$info['address'] . " ";
Print "<br>&nbsp;&nbsp;&nbsp;".$info['city'] . ", ";
Print "".$info['state'] . "&nbsp;&nbsp;";
Print "".$info['zip'] . " ";
Print "<br>&nbsp;&nbsp;&nbsp;".$info['phone'] . " ";
Print "<br><b>Main Category:</b> ".$info['cat1'] . " ";
Print "<br>&nbsp;&nbsp;&nbsp;<b>Sub Category:</b> ".$info['subcat1'] . " ";
Print "<br>&nbsp;&nbsp;&nbsp;<b>Sub Category:</b> ".$info['subcat2'] . " <br><hr> </td></tr>";
}
Print "</table>";

You can echo $count within your while loop (eg. for row numbers) or after the loop (for total rows).


Matti Ressler
Suomedia

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.