我首先搜索所有问题信息。来自"问题"表格包括标题,内容,用户等 守则:
$sql = "select * FROM question where id>0 ORDER BY id ASC";
$result1 = mysql_query($sql);
$res=Array();
然后我想从"用户"中搜索用户的观点。表。所以我必须从result1搜索每一行中每个用户的点 守则:
while($rows=mysql_fetch_assoc($result1))
{
$res[]=$rows;
$user = $rows['user'];
$sql2 = "select point from user where name='$user'";
$result2 = mysql_query($sql2);
}
我的问题是如何结合所有用户'将问题信息(result1)与point(result2)放在一起,这样我就可以为每一行返回一个json。
答案 0 :(得分:0)
最好在这里加入我给你的查询。我希望它可以帮到你
select * from question q,user u where q.id>0 ORDER BY id ASC
答案 1 :(得分:0)
尝试这样的事情:使用左连接
select question.*,user.point FROM question left join user on user.name= question.name where id>0 ORDER BY id ASC
答案 2 :(得分:0)
使用左连接,因为我理解这项工作为你
$sql = "SELECT q.*, u.point AS point FROM question AS q LEFT JOIN user AS u ON q.user = u.name WHERE q.id > 0 ORDER BY q.id ASC";
$result = mysql_query($sql);