0

我有 2 页 maincontent.php 和 showcontent.php。当有人访问 maincontent.php 时,他们会看到 2 个可以单击的图像。如果他们单击图像 1,则 showcontent.php 将获取有关该图像的更多信息并显示。这工作正常,但我希望能够从 2 个表中获取数据,而不仅仅是一个。

这是 maincontent.php

<?php include('includes/connect.php');?>

<div id="maincontent_holder">
<div id="newest_shows">

<?php
$query = "SELECT * FROM tv_shows ORDER BY id DESC LIMIT 6";

$result = mysql_query($query);    

while($row = mysql_fetch_assoc($result)) {
    echo "<div id='lastest'>";

    echo "<a href='show.php?show_name=$row[show_name]'><img src='$row[show_cover]' width='110' height='160' alt='$row[show_name]'> </a>";



    echo "</div>";
}
?>
</div>


</div>

这是showcontent.php

<?php
include('includes/connect.php');
?>
<div id="maincontent_holder">
<?php

$show_name= $_GET['show_name'];

$sql1="SELECT * FROM tv_shows WHERE show_name = '$show_name'
       UNION
       SELECT * FROM show_episodes WHERE show_name = '$show_name'";

    $result1=mysql_query($sql1);    

while($row1 = mysql_fetch_assoc($result1)) {



echo "<div id='cover_img'>";
echo "<img src='$row1[show_cover]' width='110' height='160' alt='$row1[show_name]'>";
echo "</div>";

echo "<div id='show_title'>";
echo $row1['show_name'];
echo "</div>";

echo "<div id='show_info'>";
echo $row1['show_info'];
echo "</div>";

echo "<div id='show_airs'>";
echo $row1['show_airs'];
echo "</div>";

echo "<div id='show_status'>";
echo $row1['show_status'];
echo "</div>";

echo "<div id='show_top_adzone'>";



echo "</div>";

echo "<div id='show_desc'>";
echo $row1['show_desc'];
echo "</div>";
//end of show desc
echo "<div id='episode_list'>";




echo "<a href='blaa'>$row1[episode_name]</a>";
echo "</div>";

}
?>
</div>

这是我从 showcontent.php 得到的错误

警告:mysql_fetch_assoc() 期望参数 1 是资源,布尔值在第 15 行的 C:\xampp\htdocs\includes\layout\showcontent.php 中给出

4

2 回答 2

1

您应该在 SQL 查询LIKE '%{$show_name}%'之前使用 ,mysql_real_escape_string($show_name)来排除 SQL 注入。tv_shows但是,您应该确定和的柱状结构show_episodes。我认为它没有用join

SELECT s.*, e.* FROM tv_shows AS s JOIN show_episodes e ON e.show_id = s.id;
于 2013-02-09T08:40:31.180 回答
0

将您的查询更改为这样的内容

$sql1="SELECT tv_shows.*, show_episodes.* FROM tv_shows, show_episodes
       WHERE tv_shows.show_name = '$show_name' and show_episodes.show_name = '$show_name'
       and tv_shows.show_name = show_episodes.show_name";

这会成功的

于 2013-02-09T08:45:41.833 回答