Jump to content

Recommended Posts

I am working on a rating system, and I have users. The problem I have is that I need to be able to tell if the user has already rated the item already. My question is I guess, is what should I do to try and do this? Right now, my table for sure needs:

 

Columns:

id

art type

art id

total votes

total score

rating

 

But I have no idea how I am going to store the user id for each and every user. Any suggestions? I was thinking maybe trying to make an array, but not sure if there may be a easier way.

 

Thanks in advanced.

Link to comment
https://forums.phpfreaks.com/topic/47083-question-about-mysql-and-php/
Share on other sites

Use composite table. Perharps you have 2 table: Users and Arts

Add one more table "Users_Rate" with the field:

-users_id

-art_id

(Make both become primary key.)

 

So when user rated, add the user_id and the art_id into this table.

So if user had already added the same item/art, you can check on this table.

 

;D Hope this help you.

a problem im seeing, mainly due to me not explaining it well and possibly not understanding the above to it's full extent(i'm pretty sure i get  most of it) but also, id like to use one table, and there are different types, fractal, drawings, raster, etc. and I need to total them and then do math through the PHP. so i guess i'm looking for the most efficient way possible.

tables are cheap - use an extra one.  Have one with the unchanging information on a 'piece of work'. Have the other keep art_id, user_id, and rating.

 

When someone 'rates' an item, first check that the second table does not contain their user_id and art_id (presumably a unique identifier of a thing of any type).  If it does, they've already rated it. If it doesn't add a new row to that table with their user_id and art_id and rating. You don't need to track total votes, total voters, and average rating for each item as you can calculate all those at display time by searching and processing the second table.

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.