So I have a mysql table called posted_ads I want to show a statistic on the website which is the number of ads posted.
There are also 2 types of ads type1 and type2 these are in a column in the same mysql table called ad_type
So the question is what would be the shortest possible php code to show the numbers e.g:
Number of type 1 ads = XXX (e.g: 500) Number of type 2 ads = XXX
XXX being the number of ads (rows)
Code that I do have working is...
<?php $result = mysql_query("select count(1) FROM posted_ads"); $row = mysql_fetch_array($result); $total = $row[0]; echo "Number of ads " . $total; ?>
However, I want to show 2 different stats, one that shows the number of type1 ads and the number of type 2 ads. There is a column in that table called 'ad_type' and the value is either 'type 1' or 'type 2'
---- I SOLVED IT---- Thanks for all your help. But I have now figured it out. I am using 2 bits of code, one for each ad type as follows:
<?php $result = mysql_query("select count(1) FROM posted_ads WHERE ad_type = 'type1';");
$row = mysql_fetch_array($result);
$total = $row[0];
echo "Number of type 1 ads" . $total; ?>
<?php $result = mysql_query("select count(1) FROM posted_ads WHERE ad_type = 'type2';");
$row = mysql_fetch_array($result);
$total = $row[0];
echo "Number of type 2 ads" . $total; ?>