0

EDIT: The key between these 2 table is the id # of the guest.

I want to run 2 queries from 2 different tables at the same time :

I want to create a list that a host could chek out to see every person their have ever invited. I want to show the username + location of the guestinvited

 $table = query("SELECT guest FROM parties WHERE host = $uid");   

 $table2 = query("SELECT id, username, location FROM users WHERE id = $uid");

$uid is the current user checking out the history of the guests their invited.


parties table

event | guest | host

xmas | 12 | 14


users table

id | username | location

12 | caroline | NYC


How should I do that ?

4

3 回答 3

2
$query = query('SELECT `u`.`username`, `u`.`location` FROM `users` u JOIN `parties` p ON `p`.`guest` = `u`.`id` WHERE `p`.`host` = ' . $uid)
于 2013-07-05T23:40:58.457 回答
0

同时运行 2 个查询也没关系。但是如果你想得到一个变量的结果,你可以使用它

$query = SELECT id, username, location FROM users
LEFT JOIN parties 
ON users.host = parties.host
于 2013-07-05T23:57:52.387 回答
0

基本上,您需要做的就是使用 JOIN 子句。我希望下面的代码有所帮助: $sql = ("SELECT users. id, users. username, users. location, parties. guestJOIN USING (id) WHERE id= '$uid'"); $query = mysql_query($sql) or die('查询失败:' .mysql_error);

于 2013-07-06T00:00:20.493 回答