我使用$ _POST獲取order_id的值,但它並沒有安靜立即獲取。我需要先點擊按鈕「顯示食物」或任何按鈕(如下圖所示)彈出我想輸出的表格。我嘗試使用if(isset($ _ SESSION ['viewOrder']))來獲取order.php中的按鈕的值,但即使使用SESSION,它也沒有按順序獲取它。我怎樣才能得到按鈕viewOrder的價值?如何從其他頁面獲取值
如果我將WHERE order_id = $ order_id更改爲WHERE order_id = 724,它將立即彈出該數字的值(724),但它是食物表中所有我的訂單的輸出。所以我的問題是如何輸出特定order_id的正確輸出?
例子我有2個order orderid 1和order_id 2,1的值是burger和pizza,2的值是沙拉和三明治,所以當我點擊order_id 1(order.php中的View Order按鈕)時,值的食物表是漢堡和披薩只,然後當我點擊order_id 2(查看順序按鈕order.php)值應該是沙拉和三明治不漢堡和披薩。
我希望你能理解我的解釋,我希望對你們的幫助,我真的需要馬上解決這個問題。我已經在這個問題上堆了幾天了。真的很感謝你的幫助。十分感謝!
This is what I get when clicking a button inside the ordermodal.php
這是我order.php代碼。
<button type="button"
<?php if($order['order_status'] == 'Dispatched'){ ?> input style="background-color:#ffff00;color:black"
<?php } else if($order['order_status'] == 'Accepted'){ ?> input style="background-color:#0000ff;color:white" <?php } else if($order['order_status'] == 'Pending'){ ?> input style="background-color:#B0C4DE;color:black" { <?php } ?>
class="btn btn-success" data-toggle="modal" data-target="#myModal" onclick="viewOrder('<?= $order['order_id'] ?>', '<?= $order['order_id'] ?>', '<?= $order['user_id'] ?>', '<?= $date ?>', '<?= $time ?>', '<?= $order['order_deliveryCharge'] ?>', '<?= $order['order_totalAmount'] ?>', '<?= $order['address'] ?>', '<?= $order['coordinates'] ?>', '<?= $order['driver_number'] ?>', '<?= $order['order_status'] ?>')"> View Order </button>
<script>
function viewOrder(order_id, order_id, user_id, order_date, order_time, order_deliveryCharge, order_totalAmount, address, coordinates, driver_number, order_status) {
document.getElementById("titleModal").innerHTML = "Order Information";
document.getElementsByName("ORDER_ID")[0].setAttribute("value", order_id);
document.getElementsByName("ORDER_ID_MODAL_2")[0].setAttribute("value", order_id);
document.getElementsByName("user_id")[0].setAttribute("value", user_id);
document.getElementsByName("order_date")[0].setAttribute("value", order_date);
document.getElementsByName("order_time")[0].setAttribute("value", order_time);
document.getElementsByName("order_deliveryCharge")[0].setAttribute("value", order_deliveryCharge);
document.getElementsByName("order_totalAmount")[0].setAttribute("value", order_totalAmount);
document.getElementsByName("address")[0].setAttribute("value", address);
document.getElementsByName("coordinates")[0].setAttribute("value", coordinates);
document.getElementsByName("drivers_number")[0].setAttribute("value", driver_number);
document.getElementsByName("order_status")[0].setAttribute("value", order_status);
document.getElementsByName("viewOrder")[0].setAttribute("name", "viewOrder");
}
</script>
,這是我給ordermodal.php
<div class="form-group">
<label for="order_id" class="col-sm-2 control-label">Order ID</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="ORDER_ID" id="ORDER_ID" placeholder="" value="" required="required" readonly>
</div>
</div>
<?php
if(isset($_POST['ORDER_ID'])){
$order_id = trim(addslashes($_POST['ORDER_ID']));
$sql = "SELECT food_name, special_request, quantity, amount
FROM cart_tbl
WHERE order_id=$order_id";
$result = mysqli_query(connection2(), $sql);}
?>
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>Food</th>
<th>Special Request</th>
<th>Quantity</th>
<th>Amount</th>
</tr>
</thead>
<?php
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["food_name"];?></td>
<td><?php echo $row["special_request"];?></td>
<td><?php echo $row["quantity"];?></td>
<td><?php echo $row["amount"];?></td>
</tr>
<?php
}
}
?>
</table>
</div>
<div class="modal-footer">
<button type="submit" input style="background-color:##FF0000;color:white;float:left" name="showFood" id="showFood" class="btn btn-primary " onclick="if(!confirm('Are you sure you want to see food order?')){return false;}" > Show Food</button>
<button type="submit" input style="background-color:#4CAF50;color:white" name="submitDelivered" id="submitDelivered" class="btn btn-primary " onclick="if(!confirm('Are you sure you want to deliver order?')){return false;}" > Delivered </button>
<button type="submit" input style="background-color:#0000FF;color:white" name="submitAccept" id="submitAccept" class="btn btn-primary" onclick="if(!confirm('Are you sure you want to accept order?')){return false;}"> Accept </button>
<button type="button" style="background-color:#FFFF00;color:black" class="btn btn-success" data-toggle="modal" data-target="#myDropdown"> Send </button>
<button type="submit" input style="background-color:#f44336;color:white" name="submitCancel" class="btn btn-danger" onclick="if(!confirm('Are you sure you want to cancel order?')){return false;}">Cancel</button>
你幾乎找不到人來回答這類問題,粗略地說,這將涉及到一個完整的代碼和流程分析 - 我不是那個打算這樣做的人。我剛剛注意到一件事:爲什麼在函數viewOrder中發送兩次order_id參數?這樣做肯定會導致傳遞值的偏移... –
是否通過document.getElementsByName(「ORDER_ID」)[0] .setAttribute(「value」,order_id)成功設置value屬性。 ? – Cobolt
@BriceCoustillas它的好男人。無論如何,2 order_id是ORDER_ID,另一個是ORDER_ID_MODAL_2 – zxczxczxc