Jump to content

User with limeted records in DB ?


tomcat_fo

Recommended Posts

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
}
else
{
print("you have reached the limit");
}

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


hope someone can help
Link to comment
Share on other sites

assuming you already have the user's id number assigned to an $id variable, you'd just have to do this:
[code]
<?php
$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
}
?>
[/code]

hope this helps
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.