调用非对象上的成员函数rowCount() [英] Call to a member function rowCount() on a non-object

查看:131
本文介绍了调用非对象上的成员函数rowCount()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的查询有问题.我最近改用了PDO,这对我来说是新的.现在,我需要在查询中使用JOIN来从另一个表中获取数据,而无需执行两次执行.

Im having a problem with my query. I recently switched to PDO, which is kind of new to me. Now i need to use JOIN in my query to get data from another table without making two executions.

问题是,我收到此错误:

Problem is, i get this error:

Call to a member function rowCount() on a non-object

我不明白问题是什么.这是我的代码的样子:

I don't understand what the problem is. This is how my code looks like:

  $friends_string = "SELECT * FROM `friends` as F, `users` as U WHERE `F.userID` = '$sess_user' AND `F.request` = '0' AND `F.friendID` = 'U.id'";
  $friends = $db->query($friends_string);
  if ($friends->rowCount() > 0) {

while($row = $friends->fetch(PDO::FETCH_ASSOC)) {
    echo "<br /><a href='profile.php?id={$row["id"]}'>{$row["friendID"]}</a>";
  }

} else {
    echo "no Friends";
}

或者简而言之,只是查询:

Or for short, just the query:

SELECT * FROM `friends` as F, `users` as U WHERE `F.userID` = '$sess_user' AND `F.request` = '0' AND `F.friendID` = 'U.id'

我想要的是,从用户ID为session且请求为0的朋友那里获取所有行.但是然后我想获取用户中那些朋友的ID,以便我可以链接到他们的个人资料.请注意$row["id"]

What I want is, get all rows from friends where userID is session and request is 0. But then i want to get the ID of those friends in users so i can make a link to their profile. Note the $row["id"]

感谢您的反馈,不必回答我的问题,如果您发现任何问题,请发表评论.谢谢!

I appreciate any feedback, doesn't have to answer my questions, if you note any problem please comment it. Thanks!

推荐答案

不要在"table.field"周围打勾...您必须在"table..field"周围打勾.

Don't put back ticks around the `table.field` ... You have to put them around `table`.`field`

这篇关于调用非对象上的成员函数rowCount()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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