Jump to content

[SOLVED] How do I count mysql rows with specific data


pneudralics

Recommended Posts

I have a table with 5 rows:

data1

data1

data1

data1

data2

 

I want to count only data1. How can I do that?

 

Tried the below but couldn't get it to work

$select = 'SELECT * FROM data WHERE data=data1';

if ($result = mysql_query ($select)) {
while ($row = mysql_fetch_array ($result)) {
$data1 = $row['data'];
echo "$data1";             
             }
}

Why don't you just SELECT * FROM data WHERE data='data1' then use mysql_num_rows to get the number?

 

How would I echo the amount of rows with mysql_num_rows? I know how to echo the field in the while loop but not the number of rows it returns.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.