Jump to content


User with limeted records in DB ?

  • Please log in to reply
1 reply to this topic

#1 tomcat_fo

  • Members
  • PipPip
  • Member
  • 15 posts

Posted 02 October 2006 - 03:55 PM

Im making a thing with my php-website where users can enter MAX 20 items to show.

The thing i want to happen when users enter items:
1. Check if users have used their 20 records limit or no
  2.1 If they have not reached the 20 records limit the record should be inserted
  2.2 If they have reached the 20 record limit, the record is not inserted, but they get a message, telling them they have reached the limit

What im worried about is how the querry looks like that checks how many records have been inserted.

The IF part would probably look like this:

if ($records < 20)
insert the record
print("you have reached the limit");

How will the counting part look like, where the VAR $records comes from ?

hope someone can help

#2 obsidian

  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 02 October 2006 - 04:11 PM

assuming you already have the user's id number assigned to an $id variable, you'd just have to do this:
$sql = mysql_query("SELECT COUNT(*) FROM records WHERE user_id = '$id'");
if (mysql_result($sql, 0) < 20) {
  // they have 19 or fewer, let them insert it
} else {
  // show error. they have 20 already

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users