php查询没有运行? [英] php query is not running?

查看:40
本文介绍了php查询没有运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
警告:mysql_fetch_* 期望参数 1 为是资源,布尔值错误

$query="select * from fsb_profile where fsb_profile.profile_id=('select fsb_friendlist.friendlist_friendid from fsb_friendlist where friendlist_memberid='".$id."'')";
$sql=mysql_query($query);

while ($t = mysql_fetch_assoc($sql)) 
{
    echo "hai";
    echo $t["profile_name"];
}

这段代码为什么不能运行?
错误:-

警告:mysql_fetch_assoc():已提供参数不是有效的 MySQL 结果资源在D:\Project\fsbaroda\profile.php 上第186行

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\Project\fsbaroda\profile.php on line 186

推荐答案

我想你缺少 IN 子句,也不需要在子查询中使用单引号:

You are missing IN clause there i suppose, also no need for that single quote in sub-query:

$query="select * from fsb_profile where fsb_profile.profile_id IN 
 (select fsb_friendlist.friendlist_friendid from fsb_friendlist
 where friendlist_memberid='".$id."')";

或者试试这个:

$query="select * from fsb_profile where fsb_profile.profile_id =
 (select fsb_friendlist.friendlist_friendid from fsb_friendlist
 where friendlist_memberid='".$id."')";

还要确保查询成功运行 append mysql_error():

Also make sure that query runs successfully append mysql_error():

$sql=mysql_query($query) or die(mysql_error());

这篇关于php查询没有运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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