Can I select more tables using this?
$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>';
}
I want title/smalltitle from table "users" and name/text from table "gmsg"
Use this query -
"SELECT users.title, users.smalltitle, gmsg.name FROM users, gmsg $where_condition ORDER BY users.date DESC"
$where_condition
would be the condtion to match users
& gmsg
like -
$where_condition = "users.id = gmsg.user_id"; //Or whatever it is
Yes, with JOIN. Documentation for use JOIN in Mysql here .
Sample:
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");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.