0

我有一个脚本,允许管理员查看客户已下的订单,他们可以在其中决定查看订单详细信息或删除订单。用户可以订购 1 件或多件商品,为此在数据库中创建的条目具有相同的 order_id,但具有不同的 product_id。当我显示我的订单时,这些重复的条目会出现,但是我只希望每个 order_id 有 1 个条目。下面是我的功能

function viewOrdersAdmin(){
//This block grabs the orders
$order_list = "";
//Selecting all the orders in the table from that member
$sql = mysql_query("SELECT * FROM `transactions`") or die(mysql_error());

while ($transactions = mysql_fetch_array($sql)) {
    //creating variables from the information
    $order_id = $transactions["order_id"];
    $mem_id = $transactions["mem_id"];

    $order_details = mysql_query("SELECT * FROM `transactionDetails` WHERE `order_id` = $order_id") or die(mysql_error());
    $orderDetailsCount = mysql_num_rows($order_details);
    while ($row = mysql_fetch_array($order_details)) {
        //creating variables from the information
        $order_product_id = $row["Product_ID"];

        $member_details = mysql_query("SELECT * FROM `members` WHERE `mem_id` = $mem_id") or die(mysql_error());
        $memberDetailsCount = mysql_num_rows($member_details);
        while ($row2 = mysql_fetch_array($member_details)) {
            //creating variables from the information
            $order_mem_fname = $row2["mem_first_name"];
            $order_mem_lname = $row2["mem_last_name"];

        $order_list .= "Order ID:$order_id - Customer Name: $order_mem_fname $order_mem_lname  &nbsp; &nbsp; &nbsp; <a href='manage_order.php?orderid=$order_id'>View</a> &bull; <a href='manage_orders.php?deleteid=$order_id'>Delete</a><br/>";

        }
    }
}

if (count($orderDetailsCount) == 0) {
    $order_list = "You have no orders to display";
}

print_r($order_list);
}
4

1 回答 1

1
SELECT *
FROM transactions
GROUP BY order_id
于 2013-03-15T23:22:30.913 回答