簡體   English   中英

使用$ query = mysql_query選擇更多表

[英]Select more tables using $query = mysql_query

我可以使用此表選擇更多表格嗎?

$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>';
}

我想要表“ users”中的標題/小標題和表“ gmsg”中的名稱/文本

使用此查詢-

"SELECT users.title, users.smalltitle, gmsg.name FROM users, gmsg $where_condition ORDER BY users.date DESC"

$where_condition將是匹配usersgmsg的條件,例如-

$where_condition = "users.id = gmsg.user_id"; //Or whatever it is

是的,加入JOIN。 使用文件在MySQL JOIN 這里

樣品:

SELECT * FROM t1 LEFT JOIN (t2, t3, t4)
             ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c)
$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");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM