I've learned a lot from this question, on how to send multiple order information on the database. In my table rows of "order.php" is composed of rows about order information sent by the customers. My code is only for single order only. But I want to view in the other page the multiple orders sent by one customer.
Here is my code for "order.php"
<?php
session_start();
$conn = mysqli_connect('localhost','root','','sampsix');
if(mysqli_connect_errno()){
echo 'Failed to connect: '.mysqli_connect_error();
}
if(isset($_POST['delete'])){
$DeleteQuery = "DELETE FROM orders WHERE id='$_POST[hidden]'";
mysqli_query($conn,$DeleteQuery);
}
if(isset($_POST['view'])){
header('Location: view_order.php');
}
$query = "SELECT * FROM orders ORDER BY id";
$results = mysqli_query($conn,$query);
echo '<table border="1">';
echo '<tr>';
echo '<th>ID</th>';
echo '<th>Firstame</th>';
echo '<th>Lastname</th>';
echo '<th>Email</th>';
echo '<th>Order Name</th>';
echo '<th>Order Code</th>';
echo '<th>Order Qty</th>';
echo '<th>Sub Total</th>';
echo '</tr>';
while($orderData = mysqli_fetch_array($results)){
echo '<form action="order.php" method="POST">';
echo '<tr>';
echo '<td>'.$orderData['id'].'</td>';
echo '<td>'.$orderData['firstname'].'</td>';
echo '<td>'.$orderData['lastname'].'</td>';
echo '<td>'.$orderData['email'].'</td>';
echo '<td>'.$orderData['ordername'].'</td>';
echo '<td>'.$orderData['ordercode'].'</td>';
echo '<td>'.$orderData['orderqty'].'</td>';
echo '<td>'.$orderData['subtotal'].'</td>';
echo '<td><input type="hidden" name="hidden" value="'.$orderData['id'].'"></td>';
echo '<td><input type="submit" name="delete" value="Delete"></td>';
echo '</form>';
echo "<td><a href='view_order.php?id=".$orderData['id']."'>View</a></td>";
echo '</tr>';
}
echo '</table>';
mysqli_close($conn);
?>
And here is my "view_order.php" where in the order information is in there:
<?php
include_once('config.php');
if(isset($_GET['id'])){
$id = $_GET['id'];
$query = $mysqli->query("SELECT id,firstname,lastname,email,ordername,ordercode,orderqty,subtotal FROM orders WHERE id='$id'");
if($query){
while($obj = $query->fetch_object()){
echo 'ID: '.$obj->id;
echo 'Firstname: '.$obj->firstname;
echo 'Lastname: '.$obj->lastname;
echo 'Email: '.$obj->email;
echo 'Order Name: '.$obj->ordername;
echo 'Order Code: '.$obj->ordercode;
echo 'Order Qty: '.$obj->orderqty;
echo 'Sub total: '.$obj->subtotal;
}
}
}
?>
This code above also execute single order only. I just thinking what if the customers has multiple order and I want to view it all in the other page.