For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > June 2006 > Count Many Records









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Count Many Records
Kevin Murphy

2006-06-28, 6:57 pm

Thanks in advance for your help, and forgive me if this is me being
bone-headed. :-)

The following code works and accomplishes what I need it to do, but I
am wondering if there is a better way to accomplish the same task. I
have several tables of records and I need to count and then display.
Even if I could just combine the first three queries (below) into one
that would probably be a lot better than what I am doing now.

$data1_query = "select id from data1 WHERE status = ''";
$data1_results = mysql_query($data1_query);
$data1_count = mysql_num_rows($data1_results);

$data1p_query = "select id from data1 WHERE status = 'p'";
$data1p_results = mysql_query($data1p_query);
$data1p_count = mysql_num_rows($data1p_results);

$data1h_query = "select id from data1 WHERE status = 'h'";
$data1h_results = mysql_query($data1h_query);
$data1h_count = mysql_num_rows($data1h_results);

echo "<tr>";
echo "<td align=\"center\" valign=\"top\">$data1_count</td>";
echo "<td align=\"center\" valign=\"top\">$data1h_count</td>";
echo "<td align=\"center\" valign=\"top\">$data1p_count</td>";
echo "</tr>";

Then do the same thing for the second table, and so on.

$data2_query = "select id from data2 WHERE status = ''";
$data2_results = mysql_query($data2_query);
$data2_count = mysql_num_rows($data2_results);

$data2p_query = "select id from data2 WHERE status = 'p'";
$data2p_results = mysql_query($data2p_query);
$data2p_count = mysql_num_rows($data2p_results);

$data2h_query = "select id from data2 WHERE status = 'h'";
$data2h_results = mysql_query($data2h_query);
$data2h_count = mysql_num_rows($data2h_results);

echo "<tr>";
echo "<td align=\"center\" valign=\"top\">$data2_count</td>";
echo "<td align=\"center\" valign=\"top\">$data2h_count</td>";
echo "<td align=\"center\" valign=\"top\">$data2p_count</td>";
echo "</tr>";

--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326



--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com