How to fix this error “mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in”?
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
错误...
Warning: mysql_fetch_assoc() expects
parameter 1 to be resource, boolean
given in
/home/andar/public_html/sistema/admin/cron.php
on line 19
1 2 3 4 5 6 7 8 9 10 11 12 | $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(); |
要确保while只在查询成功时执行,您可以编写:
1 2 3 4 | if ($query) while($res = mysql_fetch_assoc($query)) { mysql_query("UPDATE products SET publicado = '0' WHERE auto_pub =".$hoje) or die(mysql_error()); } |
注意循环中没有
在
1 2 3 4 5 6 7 8 9 10 11 12 | $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(); |
希望能帮助到你。
可能是由于语法错误(未引用您的日期),