【发布时间】:2018-06-05 18:19:38
【问题描述】:
我有一个数据库
-movie ( movie_id , title , year)
1 , thor , 2017
2 , deadpool,2018
-genre ( genre_id , genre_name )
1 , action
2 , adventure
3 , comedy
-movie_genre ( movie_id , genre_id )
1 , 1
1 , 2
2 , 2
2 , 3
我的php代码是
<?php
$info_query = mysql_query("
SELECT *
FROM movie
, genre
, movie_genre
WHERE movie.movie_id = movie_genre.movie_id
AND genre.genre_id = movie_genre.genre_id
")or die(mysql_error());
$info_count =mysql_num_rows($info_query);
while($info_row = mysql_fetch_array($info_query)){
if ($info_count > 0){ ?>
<?php echo $info_row['title'] ?>
<?php echo $info_row['genre'] ?>
<?php
} }
?>
输出是
thor action thor adventure
我想要
thor acton adventure
deadpool adventure comedy
【问题讨论】:
-
我们很久以前就停止使用这个过时、不安全且已弃用的 API。这是为了历史利益吗?
-
警告:不要使用在 PHP 7 中删除的过时的
mysql_query接口。PDO is not hard to learn 之类的替代品和PHP The Right Way 之类的指南有助于解释最佳实践.这里的参数是 NOT properly escaped 并且在这段代码中有严重的 SQL injection bugs。转义任何和所有用户数据,尤其是来自$_POST或$_GET。