PRodgers4284 Posted March 5, 2008 Share Posted March 5, 2008 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 More sharing options...
revraz Posted March 5, 2008 Share Posted March 5, 2008 if ($count >= 4) { echo "already 4 or more rows"; } else { echo "less than 4, allow insert"; } Like that? Link to comment https://forums.phpfreaks.com/topic/94539-record-count/#findComment-484075 Share on other sites More sharing options...
craygo Posted March 5, 2008 Share Posted March 5, 2008 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 More sharing options...
PRodgers4284 Posted March 5, 2008 Author Share Posted March 5, 2008 Thanks guys, appreciate ur help Link to comment https://forums.phpfreaks.com/topic/94539-record-count/#findComment-484084 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.