View Single Post
Old 09-26-2010, 10:22 AM   #1 (permalink)
aahwaan
The Visitor
Newcomer 
 
Join Date: Sep 2010
Location: India
Posts: 1
Thanks: 0
aahwaan is on a distinguished road
Default How do I count the number of rows with certain data

I have a database with the following fields

id (primary id)
name (name of member)
city (cities where he has lived, comma separated values)

I have this sample database
id | Name | City
1 | Jyoti | Mumbai, Delhi
2 | Preeti | Delhi, Kolkata
3 | Nyasa | Mumbai, Boston, NewYork
4 |Nini | Delhi, Chennai
5 | Pinku | Pune, Mumbai

Now I wish to know how many members are from "Mumbai"

$result = mysql_query("SELECT * FROM members");
$row = mysql_fetch_array($result);
$city = $row['city'];
//now i explode the city to find values in array
$array = explode(",",$city);
Then see individual results. Then I used
if(in_array('Mumbai' $array)){
echo $value;
}

This gives me the names
Jyoti
Nyasa
Pinku

How Do I count the numbers of these, I mean how do I reach at a result of '3'. Anyone please help me.

N.B. I tried to use count() for the query that failed me. I do not know what other method is there since I am new to Php MySQL.

Please help me...
aahwaan is offline  
Reply With Quote