我已经做了一张表格,以便员工可以在餐厅的桌子上接单。 当人员为客户进行预订时,数据库中会生成一个预订ID。
我想做的是在Orders.Res_ID上加入reserveringen.Reservering_Id,这样我下订单时就不必手动输入Res_ID。我只想输入日期和表格,然后知道属于哪个预订。
这是我正在使用的语句,它可以正常工作,但是即使我的数据库中有保留,reservation_id仍为空。
$sql = "SELECT O.Res_Datum, O.Res_ID, O.Tafel_Id,O.ReceiptID, SUM(MI.ItemPrice) AS TotalReceiptPrice
FROM Orders AS O INNER JOIN MenuItem AS MI ON O.MenuItemID = MI.MenuItemID
GROUP BY O.Res_Datum, O.Res_ID, O.Tafel_Id ";
这给了我他们在特定日期订购的总金额。 我唯一不知道的是什么reservering.Reservering_Id坐在那张桌子上。
这是查询的结果: 我手动输入了此价格,但总价格确实可以计算和工作。
Res_datum: 2019-01-21 ReservationID : 5 - Table_Number: 3 BonNummer: 3 Total Order Price: 12
Res_datum: 2019-01-22 ReservationID : 0 - Table_Number: 5 BonNummer: 2 Total Order Price: 12
我的数据库
MenuItem:
MenuItemID int(11)
ItemName varchar(255)
ItemPrice double
orders:
OrderID int(11)
MenuItemID int(11)
ReceiptID int(11)
Res_Datum date
Tafel_Id int(11)
Res_ID int(11)
receipt:
ReceiptID int(11)
ReceiptPrice double
reserveringen:
Reservering_Id int(11)
Tafel_Id int(11)
VoorNaam varchar(255)
AchterNaam varchar(255)
TelefoonNummer varchar(255)
Email varchar(255)
Res_Datum date
任何帮助将不胜感激。
这是我正在使用的一些代码:
SELECT * FROM `orders` INNER JOIN reserveringen on Orders.Res_ID = reserveringen.Reservering_Id
现在发生的是,我获得了reserveringen表中的所有信息,并且它会自动填充所有内容。 但是我确实需要手动输入reservering.Reservering_Id,现在它不再计算出总收货价格。
这是我的代码:
<form action="/restaurant/maak_bestelling.php" method="POST">
<h2>Enter Order</h2>
Table Number:<br>
<input type="text" name="tafelnummer" value=""><br><br>
Receipt Id:<br>
<input type="text" name="receiptid" value=""><br><br>
Menu_Item:<br>
<input type="text" name="menu_item" value=""><br><br>
Date: <br>
<input type="date" name="date" value=""><br><br>
<input type="submit" value="Submit">
</form>
<h2>Pending Orders:</h2>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "restaurant";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//MY Query i am trying to run
// $sql = "SELECT O.Res_Datum, R.Reservering_Id, O.Tafel_Id,O.ReceiptID, SUM(MI.ItemPrice) AS TotalReceiptPrice
// FROM Orders, Reserveringen AS O INNER JOIN MenuItem AS MI ON O.MenuItemID = MI.MenuItemID
// AS O LEFT JOIN Reservering_Id AS R on O.Reservering_Id = R.reservering_Id
// GROUP BY O.Res_Datum, O.Res_ID, O.Tafel_Id ";
//The statement I get with an Empty reservation_ID
$sql = "SELECT O.Res_Datum, O.Res_ID, O.Tafel_Id,O.ReceiptID, SUM(MI.ItemPrice) AS TotalReceiptPrice
FROM Orders AS O INNER JOIN MenuItem AS MI ON O.MenuItemID = MI.MenuItemID
GROUP BY O.Res_Datum, O.Res_ID, O.Tafel_Id ";
SELECT * FROM `orders` JOIN reserveringen on Orders.Res_ID = reserveringen.Reservering_Id
$result = $conn->query($sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "Res_datum: ". $row["Res_Datum"]. " ReservationID : " . $row["Res_ID"]. " - Table_Number: " . $row["Tafel_Id"]. " BonNummer: ".$row["ReceiptID"]." Total Order Price: " . $row["TotalReceiptPrice"]." ". "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
</div>