gpt4 book ai didi

php - 多查询和结果连接

转载 作者:行者123 更新时间:2023-11-30 01:03:32 25 4
gpt4 key购买 nike

require_once("./Connections/root.php");
session_start();
$user = $_SESSION['MM_Username'];
$q = mysql_query("SELECT id FROM performer WHERE username = '$user'");
$r = mysql_fetch_assoc($q);
$q1 = mysql_query("SELECT poster_id, wall_msg FROM performer_info WHERE id = '$r[id]'");
$r1 = mysql_fetch_assoc($q1);
$q2 = mysql_query("SELECT username FROM performer WHERE id = '$r1[poster_id]'");
$r2 = mysql_fetch_assoc($q2);

echo $r2['username'] . " : " . $r1['wall_msg'];

是否可以在单个查询和结果中使用所有这些查询?

我想,我需要使用内部联接,但我不知道该怎么做

$_SESSION['MM_Username'] 是登录的用户,用户名

最佳答案

您可以使用类似的查询

select wall_msg from performer_info where poster_id = (select id from performer where username = '$user')

您已经知道的用户名...并且 wall_msg 可以从此查询结果中获得。

编辑:

 select p.username, t.wall_msg from performer p, (select poster_id, wall_msg from performer_info where id=(select id from performer where username= '$user'))t where p.id = t.posterid;

只有当内部查询返回单个结果时,这才有效。希望对您有所帮助。

关于php - 多查询和结果连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19874776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com