[英]How can I fetch one order from database instead of all?
这是我的billingHistory.php文件';
include 'systemMenu.php'; echo '<h4>All Charges</h4>'; $user = unserialize($_SESSION['user']); $query = "SELECT * FROM billingItems WHERE userID='".$user->userID. " ' GROUP BY deliveryTimestamp DESC"; $result = mysqli_query($db, $query); while($row = mysqli_fetch_array($result)){ echo '<p>'; echo '<a href="billingHistory1.php?deliveryTimestamp=' .$row["deliveryTimestamp"]. '">'. ' Order Delivered on' . '</a>' .$row['deliveryTimestamp'] ; } echo '</div></body></html>'; $_SESSION['user'] = serialize($user); include 'footer.html'; ?>
这是我的billingHistory1.php
<?php
include 'preCode.php';
include 'header.php';
echo '<body><div class="standardLayout">';
include 'systemMenu.php';
echo '<h2>All Charges</h2>';
$user = unserialize($_SESSION['user']);
$query = "SELECT * FROM billingItems WHERE userID='" .$user->userID. "' AND DELIVERYTIMESTAMP='" .$_REQUEST["deliveryTimestamp"]. "' ORDER BY deliveryTimestamp DESC";
$result = mysqli_query($db, $query);
while($row = mysqli_fetch_array($result)){
echo '<p>';
echo '<p>'. $row['type'] . '<br>' .
'Cost: $' . $row['amount'] . '<br>' . '</p>' ;
}
echo '<h2>Order History</h2>';
$query1 = "SELECT * from Orders WHERE userID = '" . $user->userID . "' AND delivered = '1' GROUP BY ID DESC";
$result1 = mysqli_query($db, $query1);
while ($row1 = mysqli_fetch_array($result1)){
echo '<p>';
echo $row1["produce"] . ',' . $row1["meat"] . ',' . $row1["bakeryBread"] . ',' . $row1["frozen"] . ',' . $row1["dairy"] . ',
' . $row1["snacks"] . ',' . $row1["cannedFood"] . '</p>' ;
}
echo '</div></body></html>';
$_SESSION['user'] = serialize($user);
include 'footer.html';
?>
这是我的第一个输出:(交付的订单是一个超链接)
All Charges
Order Delivered on2015-05-16 14:48:17
Order Delivered on2015-05-16 14:46:21
这是我的第二个输出:(当客户单击“订单已交付”(超链接)时,它将显示所有费用以及与该费用相关的一个订单历史记录,而不是显示所有订单历史记录。
All Charges
Grocery Cost
Cost: $2.49
Shopping & Delivery
Cost: $0.00
Order History
1 Chilli,fish,bread,ice,milk, ,
2 Tomatoes,,,,, ,
您需要添加一个这样的限制:
SELECT * FROM billingItems WHERE userID='".$user->userID. " ' GROUP BY deliveryTimestamp DESC LIMIT 1
...或将您的WHERE子句扩展为更具限制性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.