php - Mysql 查询不起作用?

标签 php mysql pdo

我正在为我的网站制作一个简单的好友功能,当人们收到好友请求时,我希望它显示在好友面板链接上,所以我尝试了这个。

 $q = $dbc -> prepare("SELECT id_to read FROM friend_requests WHERE id = ? && read == '0'");
 $q -> execute(array($details['id']));
 $request_count = $q -> rowCount();
 if ($request_count > 0) {
echo '<li><a href="/friends"><img src="/gameimages/friends.png" height="16" width="16" alt="" /><strong>Friends (' . $request_count . ')</strong></a></li>';
 }
 else {
echo $request_count;
echo '<li><a href="/friends"><img src="/gameimages/friends.png" height="16" width="16" alt="" />Friends </a></li>';
 }

现在在显示请求的 friend 页面上,所有请求都将读取列设置为 1,默认情况下为 0。如果有行为 0,则它应该是一个新请求,上面的查询应该触发让用户知道他们有新的要求,我做错了什么?

最佳答案

问题是您的查询:

SELECT id_to read FROM friend_requests WHERE id = ? && read == '0'

应该是

SELECT id_to, read FROM friend_requests WHERE id = ? and read = '0'

关于php - Mysql 查询不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7409212/

相关文章:

php - 多个 like 或多个 where 子句

php - 优化 MySQL 全文搜索

php - 将mysql数据库与Android应用程序连接

php - 为什么这个 PDO 语句会默默地失败?

php - Doctrine原生查询(createNativeQuery) select查询100万行高内存占用

php - Jquery ui sortable 不创建数组

php json_encode 带有西里尔字符

mysql - SQL 按给定行列出包含 '1' 的列

php - sql 时间差函数

php - 嵌套数组/连接可以用 Php::PDO 完成吗?