Jump to content

counting results from a mysql database


otamendi

Recommended Posts

 

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.

 

Link to comment
https://forums.phpfreaks.com/topic/59180-counting-results-from-a-mysql-database/
Share on other sites

$sql = "select * from classifieds where user='$username'";
$result = mysql_query($sql);
$numRows = mysql_num_rows($result);
while($row = mysql_fetch_array($result)
{
// your code here
}

 

the number of rows returned will be stored in the $numRows variable.

 

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.