我希望能够匹配Table1中的字段和Table1中的echo数据以及Table2中的匹配字段。我试过以下但没有用。
示例:
我想按此顺序回显数据:items(Table1), category(Table1), preice(Table2), buyer(Table1)
$serchRslt = "fr732001";
$result = mysql_query("SELECT Table1.items, Table1.category, Table1.buyer, Table2.price, Table2.stocks Table2
LEFT OUTER JOIN Table1 ON Table2.item = Table1.items FROM Table1 WHERE Table1.items = '".$serchRslt."'");
while($line = mysql_fetch_array($result)) {
echo $line["items"];
echo $line["category"];
echo $line["price"];
echo $line["buyer"];
}
预期结果:fr732001 fruits 3.20 AS1
答案 0 :(得分:1)
您的Sql语法看起来有点不稳定。尝试:
SELECT
Table1.items,
Table1.category,
Table1.buyer,
Table2.price,
Table2.stocks
FROM Table1
LEFT OUTER JOIN Table2 ON Table2.item = Table1.items
WHERE Table1.items = $...
答案 1 :(得分:0)
查询应该是
SELECT Table1.items,
Table1.category,
Table1.buyer,
Table2.price,
Table2.stocks
from Table1
LEFT OUTER JOIN Table2
ON Table2.item = Table1.items
WHERE Table1.items = 'fr732001';