0

在这里我的连接查询出现问题..我不知道我的查询是否错误或其他问题出在哪里,但它给出的错误是

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in     C:\xampp\htdocs\project\teacher\courses-list.php on line 46

这是我的代码,请修改代码,我不会发现问题.. :( courses-list.php

<?php
 if ($_SESSION["isteacher"])
{

$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con)
{
die('Could not connect: ' . mysql_error());

}
mysql_select_db($dbname, $con);
$result = mysql_query("SELECT courses.id AS cid, courses.title, courses.description,    courses.subjects-id, subjects.id AS sid, subjects.subjectname AS sname FROM courses,    subjects WHERE (courses.subjects-id==subjects.id)");
echo "<table border='1'> <br />
<tr>
<th>ID:</th>
<th>Course Name</th>
<th>Description</th>
<th>Subject-ID</th>
<th>EDIT</th>
<th>DELETE</th>
</tr>";

while($row = mysql_fetch_array($result)) // this is the error line
{
echo "<tr>";
echo "<td>" . $row['cid'] . "</td>";
echo "<td>" . $row['title'] . "</td>";
echo "<td>" . $row['description'] . "</td>";
echo "<td>" . $row['sname'] . "</td>";
echo "<td><a href='courses-edit.php?id=" . $row['id']."'>EDIT</a></td>";
echo "<td><a href='courses-delete.php?id=" . $row['id']."'>DELETE</a></td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);
?>
4

1 回答 1

1

这是错误

 $result = mysql_query("SELECT courses.id AS cid, courses.title, courses.description,    courses.subjects-id, subjects.id AS sid, subjects.subjectname AS sname FROM courses,    subjects WHERE (courses.subjects-id==subjects.id)");

应该

$result = mysql_query("SELECT courses.id AS cid, courses.title, courses.description,    courses.subjects-id, subjects.id AS sid, subjects.subjectname AS sname FROM courses,    subjects WHERE (courses.subjects-id=subjects.id)");

错误部分是

subjects WHERE (courses.subjects-id==subjects.id)");
        here is the error ---------^^--------sould be =

请避免甚至不使用mysql_*php 手册显示有关使用 mysqli 或 PDO 的消息

于 2012-09-24T17:07:01.887 回答