homepage Welcome to WebmasterWorld Guest from 50.16.130.188
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
multiple entries for one field type
cdphp




msg:4098875
 3:59 pm on Mar 16, 2010 (gmt 0)

hi im doing a website for nightlife in london. a user can rate the place they go to out of 1-10. im doing the database on phpmyadmin. i want the user to be able to rate the place as many times as they like. im not sure how to do it so would i be able to get assistance?

thanks in advance

 

rocknbil




msg:4098970
 6:37 pm on Mar 16, 2010 (gmt 0)

table users
id|user_id|fname|.....

table ratings
id|user_id|location_id|rating|.....

Like that, joined on user_id? Users would have multiple rows in ratings. You could do a sum or display individual ratings for each location.

cdphp




msg:4098990
 7:28 pm on Mar 16, 2010 (gmt 0)

would i make user_id primary key on both tables?

LifeinAsia




msg:4099065
 8:57 pm on Mar 16, 2010 (gmt 0)

i want the user to be able to rate the place as many times as they like.

DB structure aside, this sounds like a recipe for spamming your site.

Dijkgraaf




msg:4099090
 9:40 pm on Mar 16, 2010 (gmt 0)

would i make user_id primary key on both tables?


No, in the example given above, id is the primary key in both tables and user_id is a foreign key in the ratings table.
However personally I would make the ID fields a bit more distinct and not have two different id fields in the user table as below.

table User
User_ID|Firstname|.....

table Rating
Rating_ID|User_ID|Location_ID|Rating|.....

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved