Jump to content

Count rows on a SELECT FROM WHERE result


slj90

Recommended Posts

 $result = mysql_query("SELECT *  FROM `friend_system` WHERE `friend_system_accepter` = '$myusername' ");
echo mysql_num_rows($result);

This displays the total rows in the table.

$result = mysql_query("SELECT COUNT(friend_system_accepter)  FROM `friend_system` WHERE `friend_system_accepter` = '$myusername' ");
echo mysql_num_rows($result);

This displays '1', which is incorrect.

 

I want to echo out the number of rows where 'friend_system_accepter' = $myusername

 

Thanks

example

$sql = "SELECT COUNT(*) as tot 
        FROM mytable 
        WHERE data = 'x'";
$res = mysql_query($sql);
$row = mysql_fetch_assoc($res);
echo $row['tot'];                 // --> number of records

NB: Stop using mysql_xxx functions and change to mysqli_xxx or PDO

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.