0

可能重复:
警告:mysql_fetch_* 期望参数 1 是资源,布尔给定错误

我是PHP的新手,所以我为混乱的代码道歉..

我不知道如何解决这个错误:

警告:mysql_fetch_array() 期望参数 1 是资源,布尔值在第 6 行的 C:\xampp\htdocs\final2\ah.php 中给出

请帮助我了解如何解决这个问题。

这是我的php代码:

<?php

    include('config_db.php');
    $today = (date('Y-m-d'));
    $query = "select * from inventory.reservation,inventory.machine where inventory.reservation.item_code = inventory.machine.item_code and inventory.reservation.date_to > '$today'";
    $result = mysql_query($query);
    while($row = mysql_fetch_array($result))
    {
        $this->avail_num = $row['avail_num'] + $row['num_reserve'];
        $this->num_reserve = 0;
    }   
    $query = "delete from inventory.reservation where num_reserve = 0";
    mysql_query($query) or die('<p>ERROR, query Failed</p>');
?>
4

3 回答 3

2

您必须使用and而不是第二个 where 子句

$query = "select * from inventory.reservation,inventory.machine where inventory.reservation.item_code = inventory.machine.item_code and  inventory.reservation.date_to > '".$today."'";
于 2012-09-22T05:03:16.603 回答
1

改变

$query = "select * from inventory.reservation,inventory.machine where inventory.reservation.item_code = inventory.machine.item_code where  inventory.reservation.date_to > '$today'";

$query = "select * from inventory.reservation,inventory.machine where inventory.reservation.item_code = inventory.machine.item_code AND inventory.reservation.date_to > '$today'";

您在查询中包含了两个 where ..

于 2012-09-22T05:04:27.333 回答
0

只需用“and”替换第二个“where”子句,它应该可以工作:

试试这个:

select * from inventory.reservation,inventory.machine where inventory.reservation.item_code = inventory.machine.item_code and inventory.reservation.date_to > '$today'";

注意:如果可能,请使用带有别名的列名从数据库中获取数据:如下所示:

SELECT tbl1.Column1 AS 'CusomName', tbl1.Column2 AS 'CustomName',... FROM 'Table1' tbl1 WHERE Condition1 = Condition2 AND Condition3 = Condition4

这可能会帮助您编写复杂的查询,并且在连接两个表时非常有用。

于 2012-09-22T05:30:56.210 回答