mysql - PHP show number of rows in a table with conditions -


so have mysql table called posted_ads want show statistic on website number of ads posted.

there 2 types of ads type1 , type2 these in column in same mysql table called ad_type

so question shortest possible php code show numbers e.g:

number of type 1 ads = xxx (e.g: 500) number of type 2 ads = xxx

xxx being number of ads (rows)

code have working is...

<?php $result = mysql_query("select count(1) posted_ads"); $row = mysql_fetch_array($result); $total = $row[0]; echo "number of ads " . $total; ?> 

however, want show 2 different stats, 1 shows number of type1 ads , number of type 2 ads. there column in table called 'ad_type' , value either 'type 1' or 'type 2'

---- solved it---- help. have figured out. using 2 bits of code, 1 each ad type follows:

<?php $result = mysql_query("select count(1) posted_ads 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) posted_ads ad_type = 'type2';"); $row = mysql_fetch_array($result); $total = $row[0]; echo "number of type 2 ads" . $total; ?> 

this might help:

select count(*) posted_ads group ad_type 

Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -