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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.