守则:
$query = "SELECT * FROM tweets WHERE read=n";
$result = mysqli_query($mysqli,$query);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
echo $row["from_user"], $row["text"];
上面的代码给了我这个:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /index.php on line 16
以下代码不会:
$query = "SELECT * FROM tweets";
$result = mysqli_query($mysqli,$query);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
echo $row["from_user"], $row["text"];
“读取”字段为ENUM('y','n')。
答案 0 :(得分:2)
read
是MySQL中的保留关键字。因为它是列的名称,所以在WHERE子句中添加反引号,这应该可以解决问题:
SELECT * FROM tweets WHERE `read` = 'n';
答案 1 :(得分:1)
您需要引用ENUM
值,以及转义read
,which is a reserved word in MySQL:
$query = "SELECT * FROM tweets WHERE `read` = 'n'";