如果我在PHP中使用下面的行的MySQL查詢工作完全正常:INNER JOIN與*,但不是一個單一的野外工作
$query = "
SELECT *
FROM customers_1
JOIN customers_2
ON customers_1.id = customers_2.cus_id;
";
但是當我嘗試只得到兩個單場這樣的:
$query = "
SELECT customers_1.product,customers_1.id
FROM customers_1
JOIN customers_2
ON customers_1.id = customers_2.cus_id;
";
它根本不工作,意味着我沒有得到任何輸出。當我複製並粘貼第二個查詢並將其放入PHPMyAdmin時,它工作得很好。因爲你只是fetch one column
從查詢SELECT customers_1.product..
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
if($row['id']=="3")
{
foreach($row as $field)
{
echo $field;
}
}
}
mysql_close($dbhandle);
檢查兩個表中是否存在「產品」列。 – Pupil
查詢中的id字段($ row ['id'])在哪裏? –
mysql_ *擴展在PHP 5.5.0中被棄用。 [MySQLi](http://php.net/manual/en/book.mysqli.php)或[PDO_MySQL](http://php.net/manual/en/ref.pdo-mysql.php)擴展應該使用 –