Hi there guys,
I'm sorry to bother everyone, but I've been teaching myself php by disassembling other scripts, and taking the parts I need to make the script I want to write. I search Google for what I don't understand, and then view php.net for help with arguments on the functions, but there's still a lot that I don't understand, and I KNOW that there's a lot I'm doing wrong.
I wanted to get the count of a DB table, and print the outcome for a "statistics" page on the testimonials admin section, and I found a section of a forum script that showed the count of posts in the forum index, and I used that to come up with the following. It seemed like a lot of script for 3 simple numbers, so I thought that maybe I'm doing this in a very inefficient way. I thought that maybe I can get all three numbers by querying the DB only one time.
Can someone tell me if this an acceptible way to show: total, approved & waiting in a table? Also, although the forum kept using the same var, and filling it with each new category count, I changed each one. I shouldn't keep the variable name the same in each function, should I($num for total, $num for approved and $num for waiting)?
echo ("
<p><b>Current statistics:</b></p>
<ul>
<li>Total Testimonials: ");
$query = mysql_query("SELECT * FROM testimonials");
$total = mysql_num_rows($query);
if($total==0)
{
echo ("0");
}else{
echo $total;
}
echo ("</li>
<li>Approved: ");
$query = mysql_query("SELECT * FROM testimonials WHERE active=1");
$total_app = mysql_num_rows($query);
if($total_app==0)
{
echo ("0");
}else{
echo $total_app;
echo (" (<a href=index.php?action=approved><i>view</i></a>)");
}
echo ("</li>
<li>Waiting: ");
$query = mysql_query("SELECT * FROM testimonials WHERE active=0");
$total_wait = mysql_num_rows($query);
if($total_wait==0)
{
echo ("0");
}else{
echo $total_wait;
echo (" (<a href=index.php?action=waiting><i>view</i></a>)");
}
echo ("</li>
</ul>
");
Thank you all very much for your time,
json