我可以使用此选择更多表吗?
$table = "users";
$query = mysql_query("SELECT title, smalltitle, FROM $table ORDER BY date DESC");
while($result= mysql_fetch_array($query))
{
echo'<div id="title"> ';
echo'<p>'.$result['title'].'</p>';
echo'</div>';
echo'<div id="name"> ';
echo'<p>'.$result['name'].'</p>';
echo'</div>';
}
我希望表格“用户”中的title / smalltitle和表格“gmsg”中的名称/文字
答案 0 :(得分:1)
使用此查询 -
"SELECT users.title, users.smalltitle, gmsg.name FROM users, gmsg $where_condition ORDER BY users.date DESC"
$where_condition
将成为匹配users
&amp;的条件。 gmsg
喜欢 -
$where_condition = "users.id = gmsg.user_id"; //Or whatever it is
答案 1 :(得分:0)
是的,加入。在Mysql here中使用JOIN的文档。
示例:
SELECT * FROM t1 LEFT JOIN (t2, t3, t4)
ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c)
答案 2 :(得分:0)
$table = "users";
$table2 = "gmsg";
$query = mysql_query("SELECT a.title, a.smalltitle, b.name, b.text FROM $table a, $table2 b ORDER BY a.date DESC");