TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 09-26-2010, 10:22 AM   #1 (permalink)
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
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
feedback on my class please frostyboy33 Advanced PHP Programming 7 10-22-2012 09:12 AM
How to get row number from 2 top numberd rows ttmtake General 5 01-28-2009 11:16 PM
Venerable methods and the applications they are commonly trusted in. Village Idiot Tips & Tricks 7 11-06-2008 07:36 AM
how to get the rows affected(not number of rows) kororo203 Absolute Beginners 2 04-23-2008 08:32 AM
Tips: PHP security Village Idiot Tips & Tricks 22 11-23-2007 11:17 PM


All times are GMT. The time now is 03:36 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design