0
我想顯示一些存儲在MySQL表中的特定客戶的交易記錄。如何在PHP-MySQL中以降序獲取特定客戶的交易記錄?
我試過follwing:
<table>
<tr>
<th>Transaction ID</th>
<th>Customer ID</th>
<th>Description</th>
<th>Amount</th>
<th>Date</th>
</tr>
<?php
$stmt0 = $mysqli->prepare("SELECT id FROM customers WHERE status = ?");
$stmt0->bind_param('i',$status);
$stmt0->execute();
$stmt0->store_result();
$stmt0->bind_result($cust_id);
while ($stmt0->fetch())
{
$stmt = $mysqli->prepare("SELECT id,description,amount,date FROM transactions WHERE cust_id = ? ORDER BY id DESC");
$stmt->bind_param('i',$cust_id);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($id,$description,$amount,$date);
while ($stmt->fetch())
{
?>
<tr>
<td><?php echo $id; ?></td>
<td><?php echo $cust_id; ?></td>
<td><?php echo $description; ?></td>
<td><?php echo $amount; ?></td>
<td><?php echo $date; ?></td>
</tr>
<?php
}
$stmt->close();
}
$stmt0->close();
?>
</table>
它顯示了特定客戶的交易記錄,按我的要求,但它通過「CUST_ID」分組顯示的記錄。我需要按降序排列「id」來顯示它們。
請幫忙!
你的意思是通過訂購'id'整個列表中'cust_id'不論降序排列? –
@pro_cheats yes .. –