-1

如何显示电影的评论?

这是我的查询 -

$query = "SELECT movies.movie_id, movies.movie_title, 
                    FROM movies
                    INNER JOIN reviews
                    ON reviews.review_id=reviews.fk_movie_review";




CREATE TABLE IF NOT EXISTS `movies` (
  `movie_id` int(4) NOT NULL AUTO_INCREMENT,
  `movie_title` varchar(100) NOT NULL,
  `actor` varchar(100) NOT NULL,
  `fk_movie_ratings` int(2) NOT NULL,
  PRIMARY KEY (`movie_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--


INSERT INTO `movies` (`movie_id`, `movie_title`, `actor`, `fk_movie_ratings`) VALUES
(1, 'Batman Begins', 'Christian Bale', 5);



CREATE TABLE IF NOT EXISTS `ratings` (
  `rating_id` int(2) NOT NULL,
  `rating_name` varchar(50) NOT NULL,
  PRIMARY KEY (`rating_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;



INSERT INTO `ratings` (`rating_id`, `rating_name`) VALUES
(1, 'Excellent'),
(2, 'Brilliant'),
(3, 'Good'),
(4, 'Ok'),
(5, 'Terrible');



--
-- Table structure for table `reviews`
--

CREATE TABLE IF NOT EXISTS `reviews` (
  `review_id` int(4) NOT NULL AUTO_INCREMENT,
  `movie_review` mediumtext NOT NULL,
  `fk_movie_review` int(4) NOT NULL,
  PRIMARY KEY (`review_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;



INSERT INTO `reviews` (`review_id`, `movie_review`, `fk_movie_review`) VALUES
(1, 'Wicked', 1);
4

3 回答 3

1
$query = "SELECT movies.movie_id, movies.movie_title, reviews.*
                    FROM movies
                    INNER JOIN reviews
                    ON movies.movie_id=reviews.fk_movie_review";

加入条件不参考电影表?

正如托马斯安德鲁斯所发现的那样,您还需要更多的选择列

于 2013-09-10T19:42:32.907 回答
1

您的连接有问题您已在表的ON子句中指定了两列review您尚未加入电影表

SELECT movies.movie_id, movies.movie_title,reviews.movie_review
FROM movies
INNER JOIN reviews
ON movies.movie_id=reviews.fk_movie_review
于 2013-09-10T19:42:56.000 回答
0

尝试这个:

SELECT MOVIES.MOVIE_ID, 
       MOVIES.MOVIE_TITLE, 
       REVIEWS.MOVIE_REVIEW 
FROM   MOVIES 
       LEFT JOIN REVIEWS 
              ON REVIEWS.FK_MOVIE_REVIEW = MOVIES.MOVIE_ID 
于 2013-09-10T19:43:00.387 回答