The14thGOD Posted April 15, 2007 Share Posted April 15, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/47083-question-about-mysql-and-php/ Share on other sites More sharing options...
AndyB Posted April 15, 2007 Share Posted April 15, 2007 If you had another table containing art_id and user_id ... you would only add a row to that table if no row contained a specific art_id and user_id, i.e. that user had not already voted on that item. Quote Link to comment https://forums.phpfreaks.com/topic/47083-question-about-mysql-and-php/#findComment-229640 Share on other sites More sharing options...
xenophobia Posted April 15, 2007 Share Posted April 15, 2007 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. Hope this help you. Quote Link to comment https://forums.phpfreaks.com/topic/47083-question-about-mysql-and-php/#findComment-229644 Share on other sites More sharing options...
The14thGOD Posted April 15, 2007 Author Share Posted April 15, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/47083-question-about-mysql-and-php/#findComment-229647 Share on other sites More sharing options...
AndyB Posted April 15, 2007 Share Posted April 15, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/47083-question-about-mysql-and-php/#findComment-229651 Share on other sites More sharing options...
The14thGOD Posted April 15, 2007 Author Share Posted April 15, 2007 alrighty, i may try that then. i might as well try new things hah. thanks again for the help. Quote Link to comment https://forums.phpfreaks.com/topic/47083-question-about-mysql-and-php/#findComment-229653 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.