//( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given
不知道会遇到这个问题。请大家帮帮我。这是我的代码:
$query = "SELECT t1.employeecode, t1.employeename, t2.v, t2.w, t3.total, t3.totals
FROM invoice t1,salaries t2,table1 t3
WHERE t1.employeecode = salaries.employeecode AND
t1.employeecode = t3.employeecode
ORDER BY t1.employeecode ASC";
$result = mysql_query($query,$con);
if(mysql_num_rows($result)>0){
echo '<table><tr><th>Article title</th> </tr>';
while($row=mysql_fetch_array($result)){
//$postedon = strftime("%A %e %b %Y",strtotime($row['postedon']));
echo '<h1><tr><td><a href="3.php?employeecode='.$row["employeecode"].'">'.$row["deparment"].'</a></td></tr></h1>';
}
由于您将salaries
表别名为t2
,因此必须在where子句中将其引用为t2
:
$query = "SELECT t1.employeecode, t1.employeename, t2.v, t2.w, t3.total,
t3.totals
FROM invoice t1,salaries t2,table1 t3
WHERE t1.employeecode = t2.employeecode AND
t2.employeecode = t3.employeecode
ORDER BY t1.employeecode ASC";
$result是布尔值(false(,因为您的查询一定有问题。通过使用mysql_error()
、在查询中出错来帮助自己
$result = mysql_query($query,$con) or die(mysql_error());
注意:请不要在新代码中使用mysql_*
函数。它们不再被维护,并被正式弃用。
因此,使用PDO
或MySQLi
(IMO PDO是可行的(
您的查询似乎不起作用,并且返回FALSE布尔值失败。要检查在运行时动态构建后需要检查查询的原因按照以下步骤
$result=mysql_query($query(或die($query.">
".mysql_error(((;
检查错误消息。似乎必须包含一些错误的列
尝试将您的工资更改为t2..
WHERE t1.employeecode = salaries.employeecode AND
像
WHERE t1.employeecode = t2.employeecode AND
我不知道,但我所知道的是,当我们给表赋予一些别名时,我们的dbms会读取该别名,而不是本地表名。