王志东身价:sql语句中的嵌套 PHP
来源:百度文库 编辑:神马品牌网 时间:2024/08/26 18:16:10
$sql="SELECT * FROM `user` WHERE username in (select session_username from online where `session_username` != 'null') order by $paixu $desc" ;
出现错误
执行后SELECT * FROM `user` WHERE username in (select session_username from online where `session_username` != 'null') order by id desc
在MYSQL中要
SELECT * FROM `user` WHERE username in ("select session_username from online where `session_username` != 'null'") order by id desc
才可以,现在要怎么改呢
出现错误
执行后SELECT * FROM `user` WHERE username in (select session_username from online where `session_username` != 'null') order by id desc
在MYSQL中要
SELECT * FROM `user` WHERE username in ("select session_username from online where `session_username` != 'null'") order by id desc
才可以,现在要怎么改呢
现在就是需要多添加两个“"”[双引号]
只需要在需要的地方添加“\"”[反斜杠双引号]就可以了
$sql="SELECT * FROM `user` WHERE username in (\"select session_username from online where `session_username` != 'null'\") order by $paixu $desc";
如果直接这样不行的话 可以用连接符点号【.】$sql="SELECT * FROM `user` WHERE username in ("."\""."select session_username from online where `session_username` != 'null'"."\"".") order by $paixu $desc";