...

View Full Version : counting results from a mysql database



chakytori
07-10-2007, 02:23 AM
Hi, i have a mysql database and a php script that uses that.

I want to know how many results throw a query in order to know if they have reached a limit.

I.E.

$sql = mysql_query ("select * from classifieds where user='$username'");
while ($row = mysql_fetch_array($sql))
{
}

I want to check lets say that only 10 classifieds per 'username' can be created.

If ten or more classifieds are in the database for that 'username' then show error message.

PappaJohn
07-10-2007, 02:56 AM
mysql_num_rows (http://us.php.net/manual/en/function.mysql-num-rows.php) will help

ablaye
07-10-2007, 06:27 AM
Yep, mysql_num_rows is what you need.

$sql = mysql_query ("select * from classifieds where user='$username'");
$my_count = mysql_num_rows($sql);
if ($my_count >= 10)
{
//put your error message
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum