English 中文(简体)
采用2个表
原标题:useing 2 tables mysql [closed]
  • 时间:2012-04-14 20:36:13
  •  标签:
  • php
  • mysql

I am working on a web site that has a movie list. What I am looking to do is make it so the user can check of and rate the movies that they have seen. I have 2 different tables one for the users and one for the movies. This is my first attempt to have 2 tables link and as such I am not sure what the starting point on something like this. I want to use the movie ID as the identifier in the user profile. But I cant think of a good way to put that into the user database neatly.

成就

问题回答

a. 提供一个表用户:

  • UserID
  • Username
  • Date of birth, ...

表格:

  • MovieID
  • Moviename
  • Productionyear, ...

表格将:

  • LinkID
  • UserREF (here you put the userID of the user)
  • MovieREF (here you put the MovieID of the movie)
  • Rating
  • Datetime, ...

现在,你可以像现在这样与这些表格合作,但你可以做些什么,以确保你的数据保持有效:如果你对用户教育基金会和电影教育基金会施加限制,那么,如果没有相应的用户或电影,联系表中就没有线。

您需要第三张表格。 例如

user_movie_rating: user_id, movie_id, rating

阅读电影的评分

SELECT SUM(rating) / COUNT(user_id) FROM user_movie_rating WHERE movie_id = x




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签