0
//( ! ) 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>&nbsp;</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>';
        }
4

4 回答 4

2

$result 是布尔值(假),因为您的查询一定有问题。通过在查询中使用错误来帮助自己mysql_error()

$result = mysql_query($query,$con) or die(mysql_error()); 

注意请不要mysql_*在新代码中使用函数。它们不再被维护并被正式弃用

所以要么使用要么PDOMySQLiIMO PDO 是可行的方法)

于 2013-02-20T05:34:45.650 回答
2

由于您将salaries表别名为您必须在 where 子句t2中引用它: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";
于 2013-02-20T05:34:53.753 回答
0

看来您的查询不起作用并且无法返回 FALSE bool 值。要检查在运行时动态构建后需要检查查询的原因,请执行以下步骤

$result = mysql_query($query) 或 die($query."

".mysql_error());

检查错误消息。似乎必须包含一些错误的列

于 2013-02-20T05:38:02.110 回答
0

尝试将您的工资更改为 t2..

WHERE t1.employeecode = salaries.employeecode AND

喜欢

WHERE t1.employeecode = t2.employeecode AND

我不知道,但我知道,当我们为表提供一些别名时,我们的 dbms 会读取该别名,而不是该本地表名。

于 2013-02-20T05:41:57.160 回答