3
SELECT * FROM dislikes WHERE pid = $post AND uid = $userid AND like = 1;

这个查询不起作用(我不知道为什么)。一旦我使用 mysqli 执行此查询并尝试查找 num 行,我得到

注意:尝试在第 13 行的 C:\wamp\www\include\like.php 中获取非对象的属性

只是让您知道,表不喜欢当前是空的,有 4 列:id、pid、uid 和 like。

编辑:

echo "SELECT * FROM dislikes WHERE pid = $post AND uid = $userid AND like = 1;";
$result = $mysqli->query("SELECT * FROM dislikes WHERE pid = $post AND uid = $userid AND like = 1;");
$row_cnt = $result->num_rows;

这是php代码。第一行的回声输出:

SELECT * FROM dislikes WHERE pid = 2 AND uid = 3 AND like = 1;
4

1 回答 1

9

LIKE是 SQL 中的保留字

您必须分隔与 SQL 保留字冲突的列名:

SELECT * FROM dislikes WHERE pid = $post AND uid = $userid AND `like` = 1;

但是对您的错误的解释是 mysqli_query() 返回false而不是有效的查询结果。您需要检查函数的返回值以确保它是资源而不是false

另请参阅参考 - 这个错误在 PHP 中意味着什么?

于 2013-09-14T09:56:09.423 回答