對於每個客戶,我想返回:訂單的ID,姓名,地址,城市,上限,國家和總數。表名是:顧客(10條)和訂單(20條)選擇所有客戶和每個客戶的總訂單
我試過這個代碼,但它不工作
<?php
$conn = mysqli_connect('127.0.0.1','...','...','...') or die("Connection failed: " . $conn->connect_error);
$select = mysqli_query($conn,"SELECT customers.id,customers.name,customers.address,customers.city,customers.cap,customers.country COUNT(customerid) as TotalOrders FROM customers LEFT JOIN orders GROUP BY customer.id");
while($row = mysqli_fetch_array($select,MYSQLI_ASSOC))
{
$tb = <<<table
...{$row['totalorders']}...
table;
echo $tb;
}
mysqli_free_result($select);
echo $num_record = mysqli_affected_rows($conn);
$conn->close();
?>
缺少逗號?還有一個缺失的連接條件。也許如果你沒有像這樣寫完所有內容,或者閱讀錯誤信息! – Strawberry 2014-11-06 13:43:26