【发布时间】:2013-06-14 04:33:48
【问题描述】:
代码在几页上运行良好,并显示某种警告,例如“mysql_num_rows() 期望参数 1 是资源,C:\wamp\www 中给出的布尔值”......它总是让我感到困惑,因为它适用于某些页面,有时会显示一条警告消息,这让我很沮丧...请帮助...
<?php
$emp_id=$_SESSION['username'];
$s=mysql_query("select semester from faculty_advisor where emp_id = '$emp_id' ");
echo $s; //just to check if am getting the correct value
$subject=mysql_query("select * from subject_list where semester=$s");
$numrows=mysql_num_rows($subject);
if($numrows!=0)
{
while($row=mysql_fetch_array($numrows))
{
?>
<td align="center"><?php echo $row['sid']; ?></td>
<td align="center"><?php echo $row['subject_name']; ?></td>
<td align="center"><?php echo "<a class='tooltip' href=\"fac_adv_reg_confrm.php?uid=".$row['sid']."\">Edit<span>Edit User Details</span></a>"?></td>
<?php
}
}
else
{
die('Error: ' . mysql_error());
}
?>
【问题讨论】:
-
$s 回显的值是什么...您的查询只有在它是整数时才有效
-
试试这个,
select semester from faculty_advisor where emp_id = 'macs410' LIMIT 1 -
无论哪种情况,它都会返回一个结果集,您不能按原样使用它
-
Please, don't use
mysql_*functions in new code。它们不再维护and are officially deprecated。看到red box?改为了解prepared statements,并使用PDO 或MySQLi - this article 将帮助您决定哪个。如果你选择 PDO,here is a good tutorial.