ifステートメント内にwhileループがあり、ループの実行を1回しか許可していないため、コードが完全に機能していないと思います。このコードにより、管理者は注文を表示し、その注文に関するすべての情報にアクセスできます。ただし、このようなコードでは、注文に2つ以上含まれている場合でも、1つの商品しか表示されません。以下は私のphpコードブロックです
if (isset($_GET['orderid'])){
$targetID = $_GET['orderid'];
//query to find the item
$products_ordered = "";
$sql = mysql_query("SELECT * FROM `transactions` WHERE `order_id` ='$targetID' LIMIT 1");
$orderCount = mysql_num_rows($sql);
while ($transactions = mysql_fetch_array($sql)) {
//creating variables from the information
$order_id = $transactions["order_id"];
$mem_id = $transactions["mem_id"];
$OrderDate = $transactions["OrderDate"];
$ship_phone = $transactions["ship_phone"];
$ship_address = $transactions["ship_address"];
$ship_city = $transactions["ship_city"];
$ship_county = $transactions["ship_county"];
$ship_postcode = $transactions["ship_postcode"];
$ship_country = $transactions["ship_country"];
$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_details_id = $row["Order_details_ID"];
$order_product_id = $row["Product_ID"];
$order_product_price = $row["Price"];
$order_product_quantity = $row["Quantity"];
$member_details = mysql_query("SELECT * FROM `members` WHERE `mem_id` = $mem_id") or die(mysql_error());
$memberDetailsCount = mysql_num_rows($member_details);
while ($row = mysql_fetch_array($member_details)) {
//creating variables from the information
$order_mem_fname = $row["mem_first_name"];
$order_mem_lname = $row["mem_last_name"];
$product_details = mysql_query("SELECT * FROM `products` WHERE `id` = $order_product_id") or die(mysql_error());
while ($row1 = mysql_fetch_array($product_details)) {
//creating variables from the information
$product_name = $row1["product_name"];
$products_ordered = "<tr>
<td width=\"20%\">Product Name</td>
<td width=\"80%\"><label> $product_name
</label></td>
</tr>
<tr>
<td width=\"20%\">Quantity</td>
<td width=\"80%\"><label> $order_product_quantity
</label></td>
</tr>
<tr>
<td width=\"20%\">Price per Item</td>
<td width=\"80%\"><label> $order_product_price
</label></td>
</tr>";
}
}
}
}
if ($orderCount == 0) {
echo "Sorry, order doesn't exist";
exit();
}
}
そしてこれはデータを含む私のテーブルです
<table>
<tr>
<td width="20%">Order ID:</td>
<td width="80%"><label><?php echo $order_id; ?> </label></td>
</tr>
<tr>
<td width="20%">Order Date</td>
<td width="80%"><label><?php echo $OrderDate; ?> </label></td>
</tr>
<tr>
<td width="20%">First Name</td>
<td width="80%"><label><?php echo $order_mem_fname; ?> </label></td>
</tr>
<tr>
<td width="20%">Last Name</td>
<td width="80%"><label><?php echo $order_mem_lname; ?> </label></td>
</tr>
<tr>
<td width="20%">Contact Number</td>
<td width="80%"><label><?php echo $ship_phone; ?> </label></td>
</tr>
<tr>
<td width="20%">Address</td>
<td width="80%"><label><?php echo $ship_address; ?> </label></td>
</tr>
<tr>
<td width="20%">City</td>
<td width="80%"><label><?php echo $ship_city; ?> </label></td>
</tr>
<tr>
<td width="20%">County</td>
<td width="80%"><label><?php echo $ship_county; ?> </label></td>
</tr>
<tr>
<td width="20%">Post Code</td>
<td width="80%"><label><?php echo $ship_postcode; ?> </label></td>
</tr>
<tr>
<td width="20%">Country</td>
<td width="80%"><label><?php echo $ship_country; ?> </label></td>
</tr>
<?php echo $products_ordered;?>
</table>