【发布时间】:2017-09-30 16:22:04
【问题描述】:
我使用 $_POST 来获取 order_id 的值,但它并没有立即获得。我需要首先单击“显示食物”按钮或任何按钮(如下图所示)以弹出我要输出的表格。我尝试使用 if(isset($_SESSION['viewOrder'])) 在 order.php 中获取按钮的值,但即使我使用 SESSION,它也没有在 ordermodal 中得到它。如何获取按钮 viewOrder 的值?
如果我将 WHERE order_id=$order_id 更改为 WHERE order_id=724,它将立即弹出该数字的值 (724),但它是我在食物表中所有订单的输出。所以我的问题是如何为特定的 order_id 输出正确的输出?
示例我有 2 个订单 order_id 1 和 order_id 2,1 的值是汉堡和披萨,2 的值是沙拉和三明治,所以当我点击 order_id 1(在 order.php 中查看订单按钮)时,值那张食物表只有汉堡和比萨饼,然后当我点击 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属性?
-
@BriceCoustillas 没问题。无论如何,2 个 order_id 用于 ORDER_ID,另一个用于 ORDER_ID_MODAL_2
-
@Cobolt 是的兄弟
标签: javascript php jquery