Jump to content

Record count


PRodgers4284

Recommended Posts

Im looking to do a record count to count the number of rows in a table. I want to output an error message if the row count is greater than 4. I have the code echoeing the number of rows but i want the it to output an error if a user try to add more than 4 records. Im assuming i need an id statement but im not sure, can anyone provide some help or advice?

 

I have the following code so far

 

$count_sql = "select * FROM job WHERE username='" . $_SESSION["username"] . "'";
$count_result = mysql_query($count_sql);
$count = mysql_num_rows($count_result); 

echo "$count\n";

Link to comment
https://forums.phpfreaks.com/topic/94539-record-count/
Share on other sites

can also use the query to do it for you. Really no difference than you have.

 

$count_sql = "SELECT username, COUNT(username) as count FROM job WHERE username = '". $_SESSION['username']."' GROUP BY username";
$count_result = mysql_query($count_sql);
$cr = mysql_fetch_assoc($count_result);
if($cr['count'] >= 4){
echo "More than 4 records found for ".$cr['username'];
} else {
echo "Less than 4 records found for ".$cr['username;
}

 

Ray

Link to comment
https://forums.phpfreaks.com/topic/94539-record-count/#findComment-484083
Share on other sites

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.