求助 关于select where中嵌套select的sql语句的问题

wlcw16 2012-03-21 09:58:51
目前在做一个小型的微波当做毕业设计,在显示用户状态出了点问题

$sql="select * from tb_content where author =(select attractior from tb_friends where fans='".$_SESSION["nickname"]."') order by id desc limit $temp,$list_num ";
$results=mysql_query($sql,$link);
while($myrow=mysql_fetch_array($sql)) //进入了一个显示用户的循环
这是我两个表的图
现在的问题就是如果我只关注一个人,那么没问题,正常显示,关注两个人以上的话,页面就会报错,具体错误是
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\wamp\www\YourBlog\showmodel.php on line 16
...全文
714 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wlcw16 2012-03-21
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 mr_merlin 的回复:]

关注两个人以上的话,子查询能得到多个结果,所以用 'author=' 肯定会错误

SQL code
select * from tb_content where author in (select attractior from tb_friends where fans='小兔') order by id desc
[/Quote]

我明白了 谢谢你
wlcw16 2012-03-21
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 jordan102 的回复:]

select a.* from tb_content as a inner join tb_friends as b on b.attractior=a.author where b.fans='小兔' order by a.id desc

sql改成这样试试。
[/Quote]
谢谢你 成功了 能帮我说下为什么我写的是错误的么?
代码如诗 2012-03-21
  • 打赏
  • 举报
回复
关注两个人以上的话,子查询能得到多个结果,所以用 'author=' 肯定会错误

select * from tb_content where author in (select attractior from tb_friends where fans='小兔') order by id desc
一起混吧 2012-03-21
  • 打赏
  • 举报
回复
select a.* from tb_content as a inner join tb_friends as b on b.attractior=a.author where b.fans='小兔' order by a.id desc

sql改成这样试试。
wlcw16 2012-03-21
  • 打赏
  • 举报
回复

换了个图片能看到了 谢谢楼上
ehco 出来的sql语句是select * from tb_content where author =(select attractior from tb_friends where fans='小兔') order by id desc 应该没问题
我用的就是小兔这个id登陆的微博
一起混吧 2012-03-21
  • 打赏
  • 举报
回复
应该是sql语句出了问题。你可以echo $sql; 在两个人以上情况下看输出什么。
wlcw16 2012-03-21
  • 打赏
  • 举报
回复
tb_content表没有显示全 右边还有一个author列

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧