I need help with the table. They are not organized/neat and very confusing ->
The table has to look neat, understandable and not confusing like this -> (this is how the table should look like)
This is what I have achieved so far (See: OrderID 2) -> http://i.imgur.com/fj06EGB.png
Below is the code
<table>
<tr>
<th>Customer Name</th>
<th>Customer Contact</th>
<th>Customer Email</th>
<th>Order ID</th>
<th>Order Date</th>
<th>Menu Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Total Amount</th>
<th>Action</th>
</tr>
<?php
$result = $mysqli->query("SELECT * FROM `order`");
while($obj = mysqli_fetch_assoc($result)) {
$orderDate = $obj['OrderDate'];
$orderId = $obj['OrderID'];
$totalAmount = $obj['OrderTotal'];
$paymentStatus = $obj['PaymentStatus'];
$customerId = $obj['CustomerID'];
$res = $mysqli->query("SELECT CustomerName, CustomerContactNo, CustomerEmail FROM customer WHERE CustomerID=$customerId");
if($row = mysqli_fetch_assoc($res)) {
$customerName = $row['CustomerName'];
$customerContactNo = $row['CustomerContactNo'];
$email = $row['CustomerEmail'];
}
$result1 = $mysqli->query("SELECT * FROM ordermenu WHERE OrderID = $orderId");
while($obj1 = mysqli_fetch_assoc($result1)) {
$menuId = $obj1['MenuID'];
$menuQty = $obj1['menuQty'];
$result2 = $mysqli->query("SELECT * FROM menu WHERE MenuID = $menuId");
$obj2 = mysqli_fetch_assoc($result2);
$name = $obj2['MenuName'];
$price = $obj2['MenuPrice'];
?>
<tr>
<td><?php echo $customerName;?></td>
<td><?php echo $customerContactNo;?></td>
<td><?php echo $email;?></td>
<td><?php echo $orderId;?></td>
<td><?php echo $orderDate;?></td>
<td><?php echo $name;?></td>
<td>$<?php echo $price;?></td>
<td><?php echo $menuQty;?></td>
<td>$<?php echo $totalAmount;?></td>
<td>Update</td>
</tr>
<?php } ?>
<?php } ?>
</table>
Anyone help please.
First get Customers From db
Foreach customer get Orders by customerID joined with ordermenu (on ordermenu.OrderID = order.OrderID) and joined with menu (on ordermenu.MenuID = menu.MenuID)
<?php
$customerQuery = $mysqli->query("SELECT CustomerID, CustomerName, CustomerContactNo, CustomerEmail FROM customer;");
while($customer = mysqli_fetch_assoc($customerQuery)) {
$customerId = $customer['CustomerID'];
$orderQuery = $mysqli->query("SELECT * FROM `order` o LEFT JOIN ordermenu om ON o.OrderID = om.OrderID LEFT JOIN menu m ON m.MenuID = om.MenuID WHERE o.CustomerID = $customerId");
while($order = mysqli_fetch_assoc($orderQuery)) {
// do something with your customer and order record
// show in table for example
}
}
Related
i build a project about online shop and there is a page in the admin dashboard that show the information about the orders that coming from the users ..there is many tables
there is orders table with Order.php class.
there is products table with Product.php class.
there is orderdetails table with OrderDetails.php class ..in this table there is
id,order_id,product_id.
every thing is working well put i can't show the $product['name'] and $product['price']
because $orderDet return null value , I don't know how to catch the id from orderdetails table to use it to get the product table data .
the getOne function from class OrderDetails.php
//get one
public function getOne($id){
$query="SELECT * FROM `orderdetails`
WHERE `id` = '".$id."'";
$result=$this->connect()->query($query);
$orderdetails=null;
if($result->num_rows == 1)
{
$orderdetails = $result->fetch_assoc();
}
return $orderdetails;
}
Orders.php where i show the the customer's information and the orders they buy for the admin
<?php
session_start();
require_once 'classes/product.php';
require_once 'classes/Order.php';
require_once 'classes/Orderdetails.php';
require_once 'classes/Category.php';
require_once 'inc/header.php';
$ord=new Order;
$ordDet=new OrderDetails;
$prod=new Product;
$orders=$ord->getAll();
if(!isset($_SESSION['id']))
{
header('location:Login.php');
die();
}
?>
<div class="container">
<div class="row">
<div class="col-lg-12">
<table class="table">
<thead>
<tr>
<th>Customer Name</th>
<th>Customer Email</th>
<th>Customer Phone</th>
<th>Customer Address</th>
<th>Product Name</th>
<th>Product Price</th>
</tr>
</thead>
**the problem is here**
<?php
foreach($orders as $order)
{
$orderDetails=$ordDet->getOne($order['order_id']);
//var_dump($orderDetails);
$product=$prod->getOne($orderDetails['product_id']);
?>
<tbody>
<tr>
<td scope="row"><?php echo $order['customerName']; ?></td>
<td><?php echo $order['customerEmail']; ?></td>
<td><?php echo $order['customerPhone']; ?></td>
<td><?php echo $order['customerAddress']; ?></td>
<td><?php echo $product['name']; ?></td>
<td><?php echo $product['price']; ?></td>
</tr>
</tbody>
<?php } ?>
</table>
</div>
</div>
</div>
<?php require_once 'inc/footer.php';?>
that is an image when i make var_dump($orderDetails)
Try the following.
$query = "SELECT * FROM `orderdetails` WHERE `id` != ''";
// or $query = "SELECT * FROM `orderdetails` WHERE `id` != 0";
$result = $con->query($query);
while($row = $result->fetch_assoc()){
$id = $row["id"];
echo "<h3>id is now $id</id>";
}
// The following line is where your problem lies
$query = "SELECT * FROM `orderDetails` WHERE `order_id` != ''";
/* I assume you know the best way to handle the following part */
$result = $con->query($query);
echo $result[0]["order_id"]; // or $result["order_id]
As an advice you need to have a way to select only new orders that you have not processed. You would not want your selection to include orders you have handled each time you want to get new data from the table.
I have a question in relation to displaying PHP tables that should be straight forward but I cannot get my head around it at the moment so any help would be appreciated, basically what I want to do is display a team of players in a table, but display multiple tables of users with their team name display above it.
What I currently have : http://puu.sh/ilUJp/4a6ae5e47b.png
What I am looking to achieve : http://puu.sh/ilUJ8/7756033517.png
<div class="col-lg-6">
<h3>Team Name Goes Here </h3>
<?php
echo "<table class='table table-striped'>";
echo " <thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
";
while($row = mysqli_fetch_array($result)) {
$teamName = $row['teamName'];
$fName = $row['firstName'];
$surName = $row['surName'];
echo "
<tbody>
<tr>
<td>$teamName</td>
<td>$fName</td>
<td>$surName</td>
</tr>
</tbody>
";
}
echo "</table>";
?>
</div>
with my query :
$sql = "SELECT t.teamID,t.teamName,u.firstName,u.surName From users as u INNER JOIN team as t where u.teamID = t.teamID ";
I know the idea I need to do but cannot get it done, so any help would be appreciated.
Try this code
<?php $teemid=array();
while($row = mysqli_fetch_array($result)) {
if(!in_array($row['teamID'],$teemid)){
array_push($teemid,$row['teamID']);
if(!empty($teemid)){ ?>
</tbody>
</table>
</div>
<?php }
?>
<div class="col-lg-6">
<h3><?php echo $row['teamName']; ?></h3>
<table class='table table-striped'>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<?php } ?>
<tr>
<td><?php echo $row['teamName']; ?></td>
<td><?php echo $row['firstName']; ?></td>
<td><?php echo $row['surName']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
SQL Query Change as below
$sql = "SELECT t.teamID,t.teamName,u.firstName,u.surName From users as u INNER JOIN team as t where u.teamID = t.teamID ORDER BY u.teamID";
You can do this logic
$teams = "get all teams sql query";
while ($row = mysqli_fetch_array($teams)) {
$teamid = $row['teamid'];
$teamname = $row['teamname'];
$teammemberquery = "select all member in the where team = $teamid sql query";
echo "<table>";
while ($r = mysqli_fetch_array($teammemberquery)) {
$teamName = $r['teamName'];
$fName = $r['firstName'];
$surName = $r['surName'];
echo "
<tbody>
<tr>
<td>$teamName</td>
<td>$fName</td>
<td>$surName</td>
</tr>
</tbody>
";
}
echo "</table>";
}
Try as below (Please replace table column name as yours and mysql to mysqli):
<?php
$link = mysql_connect('localhost', 'root', 'root');
$db_selected = mysql_select_db('test', $link);
$sql = "SELECT t.team_id,t.team,u.fname,u.lname,u.email From users as u INNER JOIN team as t where u.team_id = t.team_id order by t.team_id ";
$result = mysql_query($sql);
?>
<html><head><title>team</title></head><body><div class="col-lg-6">
<?php
echo "<table>";
$teamName = "";
$i=0;
while($row = mysql_fetch_array($result))
{
if($teamName == "" || $teamName != $row['team'])
{
if($i!=0)
echo "</table>";
echo "<tr><td colspan='3'><h3>".$row['team']."</h3></td></tr>";
$teamName = $row['team'];
$i=0;
}
$fName = $row['fname'];
$surName = $row['lname'];
$email = $row['email'];
if($i==0)
{
echo "<table class='table table-striped'><tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>";
}
echo "<tr>
<td>$fName</td>
<td>$surName</td>
<td>$email</td>
</tr>";
$i++;
}
echo "</table>";
?>
</div></body></html>
This is my code in controller...
function get_product(){
$purchase_id=$_POST['purchase_id'];
if($purchase_id!=''){
//$post_array['cart']='';
$res = $this->db->query("select * from phppos_productdetails WHERE
purchase_id='$purchase_id'");
?>
<tr>
<th>Product Name</th>
<th>Quantity </th>
<th>Unit </th>
<th>Unit Rate</th>
<th>Action</th>
</tr>
<?php
$i=0;
foreach($res->result() as $row )
{
$sess_products[$i]['product_id'] = $row->product_id;
$sess_products[$i]['quantity'] = $row->quantity;
$sess_products[$i]['unit'] = $row->unit;
$sess_products[$i]['unit_rate'] = $row->unit_rate;
$this->session->set_userdata('sess_products',$sess_products);
$query = $this->db->query("SELECT product_name FROM phppos_product WHERE
product_id='".$row->product_id."'");
foreach ($query->result() as $row1 )
{
$product_name=$row1->product_name;
}
echo "<tr>";
echo "<td>".$product_name."</td>";
echo "<td>".$row->quantity."</td>";
echo "<td>".$row->unit."</td>";
echo "<td>".$row->unit_rate."</td>";
echo "<td><a href='javascript:void(0)' rownum='".$i."' class='remove_from_cart'><img src='images/close.png'/></a></td>";
echo "</tr>";
$i++;
}
}
}
This is function in controller that is being called by ajax call. So how do I store that query result in session array in codeigniter??
I am acessing like this
$demo_arr['cart']= $this->session->userdata('sess_products');
My idea is to click 'Delete' link and it will pass the id to another PHP page (deleteSession.php), and then execute the query in deleteSession.php. but I couldn't seems to get the id from manageSession.php
In manageSession.php,
<table align='center' border='1' cellpadding='5' cellspacing='0'>
<tr>
<th>Session Id</th>
<th>Type</th>
<th>Date & Time</th>
<th>Venue</th>
<th>Pax</th>
<th>Delete</th>
<th>Edit</th>
</tr>
<?php
$sql = "SELECT booking_id, booking_types, dates_sessions, venue_available, room_count FROM bookings_available ORDER BY dates_sessions asc";
$result = mysqli_query($link, $sql) or die(mysqli_error($link));
//mysqli_close($link);
while ($row = mysqli_fetch_array($result)) {
?>
<tr>
<td><?php echo $row['booking_id']; ?></td>
<td><?php echo $row['booking_types']; ?></td>
<td><?php echo $row['dates_sessions']; ?></td>
<td><?php echo $row['venue_available']; ?></td>
<td><?php echo $row['room_count']; ?></td>
<td><input type="button" value="Delete"/></td>
<td><input type="button" value="Edit"/></td>
</tr>
<?php } ?>
</table>
In deleteSession.php,
<?php
include "dbFunctions.php";
include "manageSession.php";
//$sql = "SELECT booking_id, booking_types, dates_sessions, venue_available, room_count FROM bookings_available";
//$result = mysqli_query($link, $sql) or die(mysqli_error($link));
$bookingId = filter_input(INPUT_GET, 'booking_id');
$deleteQuery = "DELETE FROM bookings_available WHERE booking_id = '$bookingId'";
?>
I think in deleteSession.php file code should be as follows.
$bookingId = filter_input(INPUT_GET, 'id');
OR
$bookingId = $_GET['id'];
Because you are passing get parameter as follows.
deleteSession.php?id=
And also keep anchor as follows.
Delete
In the deleteSession.php you can try and replace:
$bookingId = filter_input(INPUT_GET, 'booking_id');
with the below code:
$bookingId = $_REQUEST['id'];
Finally at the last line you have to execute the query which is stored in $deleteQuery variable, which is not executed yet by using below code:
$qry = mysql_query("DELETE FROM bookings_available WHERE booking_id = '$bookingId'");
//will show you error if not able to delete
if(!$qry)
die("Error: ".mysql_error());
Added this at line 3 and it works:
mysqli_select_db($link ,$DB);
Because in the code I have not selected the mysql database and also the query was not executing as the first parameter $link was missing.
SO i have form which consist of "Event Name" "Event Description" "Event Date" and checkbox "is important". When i check checkbox value "yes" its important, it sends to the sql value = "1" to table "is_important". Everything is all right, but i give the bootstrap style "bg-danger" for that "is_important" = 1 table and it doesnt show up. What's the problem?
You can see in the code:
<?php
if (isset($_POST['important'])) {
$error = array();
$success = array();
$eventTime = time();
$important = $_POST['important'];
$eventName = trim(mysql_real_escape_string($_POST['EventName']));
$eventDesc = htmlentities(trim(mysql_real_escape_string($_POST['EventDesc'])), ENT_QUOTES);
if (!isset($eventName) || empty($eventName)) {
$error['eventName'] = "Prasome ivesti ivykio varda";
} else if (strlen($eventName) > 32 || strlen($eventName) < 3) {
$error['eventName'] = "Ivykio pavadinimas turi buti tarp 3 ir 32 simboliu";
}
if (!isset($eventDesc) || empty($eventDesc)) {
$error['eventDesc'] = "Prasome ivesti ivykio aprasyma";
}
if (empty($error)) {
$sql = "INSERT INTO notes_list (title, description, timestamp,is_important) VALUES ('$eventName', '$eventDesc','$eventTime','$important')";
$result = mysqli_query($con, $sql);
$success[] = "SEKME !";
} else {
}
}
?>
<table class="table table-striped">
<thead>
<tr>
<th>Event name</th>
<th>Event description</th>
<th>Event date</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM notes_list ORDER BY id DESC LIMIT 10";
$result2 = mysqli_query($con, $query);
print_r($_POST);
if ($result2) {
while ($note = mysqli_fetch_assoc($result2)) {
?>
<tr<?php echo (($note['is_important'] == 1) ? "class='bg-danger'" : ""); ?>>
<td><?php echo $note['title']; ?></td>
<td><?php echo $note['description'] ?></td>
<td><?php echo date('l M jS', $note['timestamp']); ?></td>
</tr>
<?php
}
mysqli_free_result($result2);
}
/* close connection */
mysqli_close($con);
?>
</tbody>
</table>
Full Example in this picture:
https://www.dropbox.com/s/h650h2spy2487dm/chechbox.jpg?dl=0
This:
<tr<?php echo (($note['is_important'] == 1) ? "class='bg-danger'" : ""); ?>>
would render this:
<trclass='bg-danger'>
in case is_important is 1. You need a space there, before the class.