如何解决此错误"mysql_fetch_assoc()期望参数1为资源,在boolean中给出"? [英] How to fix this error "mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in"?

查看:62
本文介绍了如何解决此错误"mysql_fetch_assoc()期望参数1为资源,在boolean中给出"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
mysql_fetch_array()期望参数1成为资源,在select中给出布尔值

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

错误...

警告:mysql_fetch_assoc()期望 参数1为资源,布尔值 给定 /home/andar/public_html/sistema/admin/cron.php 在第19行

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/andar/public_html/sistema/admin/cron.php on line 19

$hoje = strtotime(date("d-m-Y"));

    $db = new DBConfig();
    $db -> config();
    $db->conn();
    $query = mysql_query("SELECT * FROM products WHERE auto_pub = ".$hoje) or die(mysql_error());

    while($res = mysql_fetch_assoc($query)) {
        $query = mysql_query("UPDATE products SET publicado = '0' WHERE auto_pub = ".$hoje) or die(mysql_error());
    }

    $db->close();

推荐答案

$query用于while之前和while内部...将变量的名称更改为$query2,例如:

$query is used before the while and inside the while... Change the name of the variable to $query2, for example:

$hoje = strtotime(date("d-m-Y"));

$db = new DBConfig();
$db -> config();
$db->conn();
$query = mysql_query("SELECT * FROM products WHERE auto_pub = ".$hoje) or die(mysql_error());

while($res = mysql_fetch_assoc($query)) {
    $query2 = mysql_query("UPDATE products SET publicado = '0' WHERE auto_pub = ".$hoje) or die(mysql_error());
}

$db->close();

希望有帮助.

这篇关于如何解决此错误"mysql_fetch_assoc()期望参数1为资源,在boolean中给出"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆