简体   繁体   中英

Limit number of insert allowed per user

When a user logs in to my website, he goes to dashboard showing links. One of the link is add course , which take him to form where he can add courses...

I want to apply a limit of 3 courses insertion by all users, so that all user will enter 3 courses only. After that, a message should appear saying limit reached

Then he has to chose a plan. Let's say I have 3 plans: A, B, C

  • A has limit of 10 courses
  • B has limit of 25 courses
  • C has limit of 50 courses

How can I do this?

You could select the number of courses inserted by the user so far.

For this to work you will need the courses to have something unique to the currently logged in user, usually you use the id of the user.

For example:

SELECT COUNT(user_id) AS numCourses
FROM courses
WHERE user_id = insert_user_id_here

Would give you a result set with one column numCourses . Which will contain the number of courses your user has created so far.

Hope this helped.

This is one way in which you can achieve this.

You can create a field like selectedplan for each user.

By default the value can be default . For plan A it can be A and so on.

i want to apply limit of 3 courses insertion by all users

When ever a user inserts a course check the selectedplan for that user and the number of of courses inserted by the user.

Something like

if(selectedplan="default" && courses<=3)
   //add new course
else if(selectedplan="A" && courses<=10)
  //add new course
else
  // "Cannot add more course, limit reached"

When plan is changed update selectedplan field.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM