Im trying to create a page that will display orders from a database. If it doesnt find any results it should be display "No results" or so. It does display it when there arent any. However, it displays on top of the headers instead of the body of the table where the results are displayed.
<div class="row">
<div class="col-md-12">
<table class="table table-striped shadow bg-white table-hover mb-3">
<thead>
<tr>
<th scope="col">Order Number</th>
<th scope="col">Image</th>
<th scope="col">Buyer Name</th>
<th scope="col">Product Name</th>
<th scope="col">Order Date</th>
<th scope="col">Price</th>
<th scope="col">Status</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
$userid = $_SESSION['userid'];
$sql = "
select
O.orderid as 'orderid', O.totalprice as 'totalprice', U.firstname as 'firstname', U.lastname as 'lastname', P.productname as 'productname', O.userid as 'userid', O.orderstatus as 'orderstatus', OS.status as 'status', OS.statusid as 'statusid', P.image as 'productPhoto'
from
orders O
INNER JOIN
users U ON
O.userid = U.userid
INNER JOIN
orderstatus OS ON
O.orderstatus = OS.statusid
INNER JOIN
products P ON
P.productid = O.productid
WHERE
P.userid = $userid AND O.orderstatus = 3;
";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if($resultCheck > 0 ){
while($row = mysqli_fetch_assoc($result)){
echo '
<tr>
<th scope="row">'.$row['orderid'].'</th>
<th scope="row">
<img src="images/'.$row['productPhoto'].'" class="img-fluid" alt="Product image" style="height:100px; width: 100px;">
</th>
<th scope="row">'.$row['firstname'].' '.$row['lastname']. '</th>
<!-- PRODUCT NAME -->
<th scope="row">'.$row['productname'].'</th>
<!-- ORDER DATE -->
<td>06/28/2020</td>
<form action="../inc/manageorders_actions.inc.php" METHOD="POST">
<input type="hidden" value=" '. $row['orderid'] .' " name="orderid">
<!-- PRICE -->
<td>'.'PHP '.$row['totalprice'].'</td>
<!-- STATUS -->
<td>
'. $row['status'] .'
</td>
<!-- ACTION -->
<td class="px-5">
<div class="row my-1 w-75">
<input type="submit" value="To pack" name="topack">
</div>
<div class="row my-1 w-75">
<input type="submit" value="Packed" name="packed">
</div>
<div class="row my-1 w-75">
<input type="submit" value="In delivery" name="beingdelivered">
</div>
<div class="row my-1 w-75">
<input type="submit" value="Delivery" name="delivered">
</div>
</td>
</form>
</tr>
';
}
}else{
echo 'No results';
}
?>
</tbody>
</table>
</div>
</div>
You can't just echo No results inside <tbody>.
<div class="row">
<div class="col-md-12">
<table class="table table-striped shadow bg-white table-hover mb-3">
<thead>
<tr>
<th scope="col">Order Number</th>
<th scope="col">Image</th>
<th scope="col">Buyer Name</th>
<th scope="col">Product Name</th>
<th scope="col">Order Date</th>
<th scope="col">Price</th>
<th scope="col">Status</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
$userid = $_SESSION['userid'];
$sql = "
select
O.orderid as 'orderid', O.totalprice as 'totalprice', U.firstname as 'firstname', U.lastname as 'lastname', P.productname as 'productname', O.userid as 'userid', O.orderstatus as 'orderstatus', OS.status as 'status', OS.statusid as 'statusid', P.image as 'productPhoto'
from
orders O
INNER JOIN
users U ON
O.userid = U.userid
INNER JOIN
orderstatus OS ON
O.orderstatus = OS.statusid
INNER JOIN
products P ON
P.productid = O.productid
WHERE
P.userid = $userid AND O.orderstatus = 3;
";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if($resultCheck > 0 ){
while($row = mysqli_fetch_assoc($result)){
echo '
<tr>
<th scope="row">'.$row['orderid'].'</th>
<th scope="row">
<img src="images/'.$row['productPhoto'].'" class="img-fluid" alt="Product image" style="height:100px; width: 100px;">
</th>
<th scope="row">'.$row['firstname'].' '.$row['lastname']. '</th>
<!-- PRODUCT NAME -->
<th scope="row">'.$row['productname'].'</th>
<!-- ORDER DATE -->
<td>06/28/2020</td>
<form action="../inc/manageorders_actions.inc.php" METHOD="POST">
<input type="hidden" value=" '. $row['orderid'] .' " name="orderid">
<!-- PRICE -->
<td>'.'PHP '.$row['totalprice'].'</td>
<!-- STATUS -->
<td>
'. $row['status'] .'
</td>
<!-- ACTION -->
<td class="px-5">
<div class="row my-1 w-75">
<input type="submit" value="To pack" name="topack">
</div>
<div class="row my-1 w-75">
<input type="submit" value="Packed" name="packed">
</div>
<div class="row my-1 w-75">
<input type="submit" value="In delivery" name="beingdelivered">
</div>
<div class="row my-1 w-75">
<input type="submit" value="Delivery" name="delivered">
</div>
</td>
</form>
</tr>
';
}
}else{
echo '<tr><td colspan="8">No results</td></tr>';
}
?>
</tbody>
</table>
</div>
</div>
The <tbody> element required <tr> and <td> before display the contents. See document here.
This is because you are outputting it directly in the body tag. You need to at least wrap it inside <tr><td>
echo "<tr><td>No results</td></tr>";
Why don’t echoing a formatted row like the results of the query? An then putting “no results” instead of data in it…
Related
I have a while loop that loops through my drivers table and populates the buttons with the drivers names
function driverMenu()
{
global $conn;
$query = mysqli_query($conn, "SELECT * FROM driver");
while ($row = mysqli_fetch_assoc($query)) {
$id = $row['DriverID'];
$name = $row['driverName'];
echo "<div class='col text-center'>
<input type='submit' name='driverNameBtn' class='btn btn-primary rounded-pill text-light' value='{$name}'></input>
</div>";
}
}
I then call that function in another page that shows jobs associated to the drivers.
What I need to figure out now is how to change the data that is shown when they click on the different driver buttons.
This is my code that shows each job currently in the database but does not filter out the jobs by driver yet. But it does sort each job by days of the week.
<?php ini_set('error_reporting', E_ALL); ?>
<?php ini_set('display_errors', 1); ?>
<?php ini_set('display_startup_errors', 1); ?>
<?php include '../header.php' ?>
<!-- Page Title -->
<div class="container-sm text-dark px-3 p-4 truckList">
<div class="row m-auto align-items-center">
<?php include '../includes/functions.php'; driverMenu();?>
</div>
</div>
<?php
global $conn;
$monday = mysqli_query($conn, "SELECT *
FROM openjobs
INNER JOIN driver ON openjobs.driverName_fk = driver.driverName
WHERE weekday(jobDate) = 0");
$tuesday = mysqli_query($conn, "SELECT *
FROM openjobs
INNER JOIN driver ON openjobs.driver_fk = driver.DriverID
WHERE weekday(jobDate) = 1");
$wednesday = mysqli_query($conn, "SELECT *
FROM openjobs
INNER JOIN driver ON openjobs.driver_fk = driver.DriverID
WHERE weekday(jobDate) = 2");
$thursday = mysqli_query($conn, "SELECT *
FROM openjobs
INNER JOIN driver ON openjobs.driver_fk = driver.DriverID
WHERE weekday(jobDate) = 3");
$friday = mysqli_query($conn, "SELECT *
FROM openjobs
INNER JOIN driver ON openjobs.driver_fk = driver.DriverID
WHERE weekday(jobDate) = 4");
?>
<!-- Truck's Weekly Job List -->
<div class="container-fluid bg-secondary darkContainer">
<div class="container py-5 px-4 p-3 webWeeklyPlanTruckCard">
<div class="row gy-2">
<div class="col-12">
<!-- Monday -->
<div class="card mondayJobCard my-1">
<div class="card-body">
<div class="row justify-content-between">
<div class="col-11">
<h5 class="card-title">Monday ...</h5>
</div>
<div class="col-1">
Add Job
</div>
</div>
<div class="row">
<div class="col pt-3">
<table class="table table-bordered table-responsive">
<thead>
<tr class="table-light">
<th scope="col" class="col-2">Job</th>
<th scope="col">Driver</th>
<th scope="col">Type</th>
<th scope="col" class="col-2">Order #</th>
<th scope="col" class="col-2">Reference</th>
<th scope="col">Pallets</th>
<th scope="col">Weight (kg)</th>
<th scope="col" class="col-2">Status</th>
</tr>
</thead>
<?php
while ($row = mysqli_fetch_assoc($monday)) {
//$id = $row['DriverID'];
$driverName_fk = $row['driverName_fk'];
$jobName = $row['jobName'];
$jobType = $row['jobType'];
$orderNumber = $row['orderNumber'];
$referenceNumber = $row['referenceNumber'];
$pallets = $row['pallets'];
$jobWeight = $row['jobWeight'];
$jobStatus = $row['jobStatus'];
echo "<tbody>
<tr>
<th>{$jobName}</th>
<th>{$driverName_fk}</td>
<td>{$jobType}</td>
<td>{$orderNumber}</td>
<td>{$referenceNumber}</td>
<td>{$pallets}</td>
<td>{$jobWeight}</td>
<td>{$jobStatus}</td>
</tr>
</tbody>";
}
?>
</table>
</div>
</div>
</div>
</div>
<!-- Tuesday -->
<div class="card tuesdayJobCard my-2">
<div class="card-body">
<div class="row justify-content-between">
<div class="col-11">
<h5 class="card-title">Tuesday ...</h5>
</div>
<div class="col-1">
Add Job
</div>
</div>
<div class="row">
<div class="col pt-3">
<table class="table table-bordered table-responsive">
<thead>
<tr class="table-light">
<th scope="col" class="col-2">Job</th>
<th scope="col">Driver</th>
<th scope="col">Type</th>
<th scope="col" class="col-2">Order #</th>
<th scope="col" class="col-2">Reference</th>
<th scope="col">Pallets</th>
<th scope="col">Weight (kg)</th>
<th scope="col" class="col-2">Status</th>
</tr>
</thead>
<?php
while ($row = mysqli_fetch_assoc($tuesday)) {
//$id = $row['DriverID'];
$driverName_fk = $row['driverName_fk'];
$jobName = $row['jobName'];
$jobType = $row['jobType'];
$orderNumber = $row['orderNumber'];
$referenceNumber = $row['referenceNumber'];
$pallets = $row['pallets'];
$jobWeight = $row['jobWeight'];
$jobStatus = $row['jobStatus'];
echo "<tbody>
<tr>
<th>{$jobName}</th>
<th>{$driverName_fk}</td>
<td>{$jobType}</td>
<td>{$orderNumber}</td>
<td>{$referenceNumber}</td>
<td>{$pallets}</td>
<td>{$jobWeight}</td>
<td>{$jobStatus}</td>
</tr>
</tbody>";
}
?>
</table>
</div>
</div>
</div>
</div>
<!-- Wednesday -->
<div class="card wednesdayJobCard my-2">
<div class="card-body">
<div class="row justify-content-between">
<div class="col-11">
<h5 class="card-title">Wednesday ...</h5>
</div>
<div class="col-1">
Add Job
</div>
</div>
<div class="row">
<div class="col pt-3">
<table class="table table-bordered table-responsive ">
<thead>
<tr class="table-light">
<th scope="col" class="col-2">Job</th>
<th scope="col">Driver</th>
<th scope="col">Type</th>
<th scope="col" class="col-2">Order #</th>
<th scope="col" class="col-2">Reference</th>
<th scope="col">Pallets</th>
<th scope="col">Weight (kg)</th>
<th scope="col" class="col-2">Status</th>
</tr>
</thead>
<?php
while ($row = mysqli_fetch_assoc($wednesday)) {
//$id = $row['DriverID'];
$driverName_fk = $row['driverName_fk'];
$jobName = $row['jobName'];
$jobType = $row['jobType'];
$orderNumber = $row['orderNumber'];
$referenceNumber = $row['referenceNumber'];
$pallets = $row['pallets'];
$jobWeight = $row['jobWeight'];
$jobStatus = $row['jobStatus'];
echo "<tbody>
<tr>
<th>{$jobName}</th>
<th>{$driverName_fk}</td>
<td>{$jobType}</td>
<td>{$orderNumber}</td>
<td>{$referenceNumber}</td>
<td>{$pallets}</td>
<td>{$jobWeight}</td>
<td>{$jobStatus}</td>
</tr>
</tbody>";
}
?>
</table>
</div>
</div>
</div>
</div>
<!-- Thursday -->
<div class="card thursdayJobCard my-2">
<div class="card-body">
<div class="row justify-content-between">
<div class="col-11">
<h5 class="card-title">Thursday ...</h5>
</div>
<div class="col-1">
Add Job
</div>
</div>
<div class="row">
<div class="col pt-3">
<table class="table table-bordered table-responsive">
<thead>
<tr class="table-light">
<th scope="col" class="col-2">Job</th>
<th scope="col">Driver</th>
<th scope="col">Type</th>
<th scope="col" class="col-2">Order #</th>
<th scope="col" class="col-2">Reference</th>
<th scope="col">Pallets</th>
<th scope="col">Weight (kg)</th>
<th scope="col" class="col-2">Status</th>
</tr>
</thead>
<?php
while ($row = mysqli_fetch_assoc($thursday)) {
//$id = $row['DriverID'];
$driverName_fk = $row['driverName_fk'];
$jobName = $row['jobName'];
$jobType = $row['jobType'];
$orderNumber = $row['orderNumber'];
$referenceNumber = $row['referenceNumber'];
$pallets = $row['pallets'];
$jobWeight = $row['jobWeight'];
$jobStatus = $row['jobStatus'];
echo "<tbody>
<tr>
<th>{$jobName}</th>
<th>{$driverName_fk}</td>
<td>{$jobType}</td>
<td>{$orderNumber}</td>
<td>{$referenceNumber}</td>
<td>{$pallets}</td>
<td>{$jobWeight}</td>
<td>{$jobStatus}</td>
</tr>
</tbody>";
}
?>
</table>
</div>
</div>
</div>
</div>
<!-- Friday -->
<div class="card fridayJobCard my-2">
<div class="card-body">
<div class="row justify-content-between">
<div class="col-11">
<h5 class="card-title">Friday ...</h5>
</div>
<div class="col-1">
Add Job
</div>
</div>
<div class="row">
<div class="col pt-3">
<table class="table table-bordered table-responsive">
<thead>
<tr class="table-light">
<th scope="col" class="col-2">Job</th>
<th scope="col">Driver</th>
<th scope="col">Type</th>
<th scope="col" class="col-2">Order #</th>
<th scope="col" class="col-2">Reference</th>
<th scope="col">Pallets</th>
<th scope="col">Weight (kg)</th>
<th scope="col" class="col-2">Status</th>
</tr>
</thead>
<?php
while ($row = mysqli_fetch_assoc($friday)) {
//$id = $row['DriverID'];
$driverName_fk = $row['driverName_fk'];
$jobName = $row['jobName'];
$jobType = $row['jobType'];
$orderNumber = $row['orderNumber'];
$referenceNumber = $row['referenceNumber'];
$pallets = $row['pallets'];
$jobWeight = $row['jobWeight'];
$jobStatus = $row['jobStatus'];
echo "<tbody>
<tr>
<th>{$jobName}</th>
<th>{$driverName_fk}</td>
<td>{$jobType}</td>
<td>{$orderNumber}</td>
<td>{$referenceNumber}</td>
<td>{$pallets}</td>
<td>{$jobWeight}</td>
<td>{$jobStatus}</td>
</tr>
</tbody>";
}
?>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-U1DAWAznBHeqEIlVSCgzq+c9gqGAJn5c/t99JyeKa9xxaYpSvHU5awsuZVVFIhvj" crossorigin="anonymous"></script>
<script src="../JS/app.js"></script>
<script src="../JS/ui.js"></script>
<?php include '../footer.php' ?>
I'm assuming everything will need to be in an if (isset) etc. but can't figure out what the condition needs to be. Nor how to get the data from the original functions.
The following is wholly untested and may have errors - so apologies but I think the initial page can be simplified by using a single sql select statement with no where clause and then use logic in PHP to determine which records are displayed based upon weekday number. In PHP you can use the date function to find the weekday number so the same block of code is repeated for each weekday number - and each table row now has the driver's name and ID to aid identification in Javascript. PHP & mySQL use a different numbering system for weekday - PHP uses 0 for Sunday whereas mySQL uses 0 for Monday!
<?php ini_set('error_reporting', E_ALL); ?>
<?php ini_set('display_errors', 1); ?>
<?php ini_set('display_startup_errors', 1); ?>
<?php include '../header.php' ?>
<!-- Page Title -->
<div class="container-sm text-dark px-3 p-4 truckList">
<div class="row m-auto align-items-center">
<?php
include '../includes/functions.php';
driverMenu();
?>
</div>
</div>
<?php
$sql='SELECT *
FROM openjobs
INNER JOIN driver ON openjobs.driverName_fk = driver.driverName';
$results = $conn->query( $sql );
$days=array(
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday'
);
for( $i=1; $i<=5; $i++ ){
printf('
<div class="container-fluid bg-secondary darkContainer">
<div class="container py-5 px-4 p-3 webWeeklyPlanTruckCard">
<div class="row gy-2">
<div class="col-12">
<!-- %1$s -->
<div class="card %2$sJobCard my-1">
<div class="card-body">
<div class="row justify-content-between">
<div class="col-11">
<h5 class="card-title">%1$s ...</h5>
</div>
<div class="col-1">
Add Job
</div>
</div>
<div class="row">
<div class="col pt-3">
<table class="table table-bordered table-responsive">
<thead>
<tr class="table-light">
<th scope="col" class="col-2">Job</th>
<th scope="col">Driver</th>
<th scope="col">Type</th>
<th scope="col" class="col-2">Order #</th>
<th scope="col" class="col-2">Reference</th>
<th scope="col">Pallets</th>
<th scope="col">Weight (kg)</th>
<th scope="col" class="col-2">Status</th>
</tr>
</thead>
',
$days[ $i ],
strtolower( $days[ $i ] )
);//close printf()
while( $row = $results->fetch_object() ) {
if( (int)date( 'w', strtotime( $row->jobDate ) )==$i ){
printf('<tbody>
<tr data-did="%9$s" data-driver="%1$s">
<th>%2$s</th>
<th>%1$s</td>
<td>%3$s</td>
<td>%4$s</td>
<td>%5$s</td>
<td>%6$s</td>
<td>%7$s</td>
<td>%8$s</td>
</tr>
</tbody>',
$row->driverName_fk,
$row->jobName,
$row->jobType,
$row->orderNumber,
$row->referenceNumber,
$row->pallets,
$row->jobWeight,
$row->jobStatus,
$row->DriverID
);
}
}
echo '
</table>
</div>
</div>
</div>
</div>';
}
?>
</div>
</div>
</div>
</div>
<!-- Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-U1DAWAznBHeqEIlVSCgzq+c9gqGAJn5c/t99JyeKa9xxaYpSvHU5awsuZVVFIhvj" crossorigin="anonymous"></script>
<script src="../JS/app.js"></script>
<script src="../JS/ui.js"></script>
<?php include '../footer.php' ?>
The driverMenu function is lightly modified to include the driver ID as an attribute to the input/button - again to aid identification in Javascript. One other change was the use of OO style syntax rather than the procedural - simply for convenience.
function driverMenu(){
global $conn;
$results=$conn->query('select * from driver');
while( $row = $results->fetch_object() ) {
printf('
<div class="col text-center">
<input type="button" data-name="driverNameBtn" class="btn btn-primary rounded-pill text-light" data-did="%s" value="%s" />
</div>',
$row->DriverID,
$row->driverName
);
}
}
The Javascript to show/hide various rows - the buttons are assign the same event handler which queries the DOM to find all table rows containing data and then shows/hides rows based upon the driver name and ID - taken from attributes assigned in the button and in the table row.
<script>
const qa=(e,n=document)=>n.querySelectorAll(e);
qa('input[ data-name="driverNameBtn" ]').forEach( bttn=>bttn.addEventListener('click',function(e){
e.preventDefault();
qa('table.table-responsive tbody tr').forEach( tr=>{
if( tr.dataset.did==this.dataset.did && tr.dataset.driver==this.value ){
tr.style.display='table-row';
}else{
tr.style.display='none';
}
})
}));
</script>
I am building a library management system using PHP, Mysql. There is a category for each book. Users will be able to see how many books there are in each category. But I can't figure out how many books there are in each category. I want to find out how many books there are in each category.
<div class="row">
<div class="col-md-12">
<!-- Advanced Tables -->
<div class="panel panel-default">
<div class="panel-heading">
Categories Listing
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>#</th>
<th>Category</th>
<th>Book Amount</th>
<th>Status</th>
<th>Creation Date</th>
<th>Updation Date</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT tblcategory.CategoryName, tblcategory.Status, tblcategory.CreationDate, tblcategory.UpdationDate from tblcategory";
$query = $dbh -> prepare($sql);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0)
{
foreach($results as $result)
{ ?>
<tr class="odd gradeX">
<td class="center"><?php echo htmlentities($cnt);?></td>
<td class="center"><?php echo htmlentities($result->CategoryName);?></td>
<td class="center">#</td>
<td class="center"><?php if($result->Status==1) {?>
Active
<?php } else {?>
Inactive
<?php } ?></td>
<td class="center"><?php echo htmlentities($result->CreationDate);?></td>
<td class="center"><?php echo htmlentities($result->UpdationDate);?></td>
<td class="center">
<a href="edit-category.php?catid=<?php echo htmlentities($result->id);?>"><button class="btn btn-primary"><i class="fa fa-edit "></i> Edit</button>
<a href="manage-categories.php?del=<?php echo htmlentities($result->id);?>" onclick="return confirm('Are you sure you want to delete?');"" > <button class="btn btn-danger"><i class="fa fa-pencil"></i> Delete</button>
</td>
</tr>
<?php $cnt=$cnt+1;}} ?>
</tbody>
</table>
</div>
</div>
</div>
<!--End Advanced Tables -->
</div>
</div>
My Database:
The Output Should be:
Calculate category wise book count by using subquery. Then use LEFT JOIN with main table. Use COALESCE() for replacing NULL value to 0.
SELECT c.CategoryName
, COALESCE(b.book_amount, 0) book_amount
, CASE WHEN c.Status = 1 THEN 'Active' ELSE 'Inactive' END Status
, c.CreationDate
, c.UpdationDate
FROM category c
LEFT JOIN (SELECT catid
, COUNT(id) book_amount
FROM book
GROUP BY catid) b
ON c.id = b.catid
ORDER BY b.book_amount DESC
I want my site to search for any product that belonged to particular size when click any size option in the table cell for desktop users but I am having two challenges
My loop for horizontal cells suppose to be incrementing from left to right like this 28D, 28DD, 28E, 28F, 28FF, 28G ...28K and then move to second line 30D --- 30k but instead it was reapeating each value 12 times horizontally like this 28D, 28D, 28D 12times and move to second line 28DD repeating it 12 times again. Please what could be the problem in my four loop?
I don't know how to put anchor tag around the table cell and how to put name = size attribute in the table cell for it to link sizeresult.php. where it will be processed by the select query
here is my code:
<div class="table-responsive"><!-- table-responsive begin -->
<table class="table table-striped table-hover" border="0" width="100%" cellpadding="5" cellspacing="5">
<thead>
<tr>
<th class="success">
<h4 class="text-center white-text">D</h4>
</th>
<th class="info">
<h4 class="text-center white-text">DD</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">E</h4>
</th>
<th class="success">
<h4 class="text-center white-text">F</h4>
</th>
<th class="info">
<h4 class="text-center white-text">FF</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">G</h4>
</th>
<th class="success">
<h4 class="text-center white-text">GG</h4>
</th>
<th class="info">
<h4 class="text-center white-text">H</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">HH</h4>
</th>
<th class="success">
<h4 class="text-center white-text">J</h4>
</th>
<th class="info">
<h4 class="text-center white-text">JJ</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">K</h4>
</th>
</tr>
</thead>
<tbody>
<?php
$count = 12; // Number of possible cells to add at once:
$i=0;
$get_sizes = "select * from sizes";
$run_sizes = mysqli_query($dbc,$get_sizes);
while ($row_sizes=mysqli_fetch_array($run_sizes)){
$size_id = $row_sizes['size_id'];
$size_name = $row_sizes['size'];
$i++;
?>
<tr>
<?php for ($i = 1; $i <= $count; $i++) {
echo "
<td value='$size_name' align='center'>
$size_name
</td>";
} // End of FOR loop.
?>
</tr>
<?php } ?>
</tbody>
</table>
</div> <!-- table-responsive end -->
</form>
sizeresult.php code is this :
$size_name=$_POST['size'];
$run_products = mysqli_query($dbc,"SELECT * FROM products INNER JOIN SIZES USING (size_id) WHERE sizes.size ='%$size_name%'");
I made the following changes
$count variable and for loop completely
created block of code to format your list of items in the way you have explained in your question grouping them by 12 in each row.
based on your request of using anchor tag i added anchor tag so that when the user clicks on it it will be taken to the sizeresult.php page and the query will be processed.
I made sure that the post and get request doesn't conflict by putting the following code right above the query in sizeresult.php
if(isset($_GET['size'])){ $size_name=$_GET['size'] } else if(isset($_POST['size'])){ $size_name=$_POST['size']; }
the following in your main page
<div class="table-responsive"><!-- table-responsive begin -->
<table class="table table-striped table-hover" border="0" width="100%" cellpadding="5" cellspacing="5">
<thead>
<tr>
<th class="success">
<h4 class="text-center white-text">D</h4>
</th>
<th class="info">
<h4 class="text-center white-text">DD</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">E</h4>
</th>
<th class="success">
<h4 class="text-center white-text">F</h4>
</th>
<th class="info">
<h4 class="text-center white-text">FF</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">G</h4>
</th>
<th class="success">
<h4 class="text-center white-text">GG</h4>
</th>
<th class="info">
<h4 class="text-center white-text">H</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">HH</h4>
</th>
<th class="success">
<h4 class="text-center white-text">J</h4>
</th>
<th class="info">
<h4 class="text-center white-text">JJ</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">K</h4>
</th>
</tr>
</thead>
<tbody>
<tr>
<?php
//$count = 12; // Number of possible cells to add at once://you don't need this too.
$i=1;
$get_sizes = "select * from sizes";
$run_sizes = mysqli_query($dbc,$get_sizes);
while ($row_sizes=mysqli_fetch_array($run_sizes)){
$size_id = $row_sizes['size_id'];
$size_name = $row_sizes['size'];
if($i==12){
echo "<td align='center'><a href='product-card.php?size=$size_name' type='button' style='text-decoration:none; color:black;' class='btn btn-block'>$size_name</a></td>";
$i=1;
echo "</tr><tr>";
}
else {
echo "<td align='center'><a href='product-card.php?size=$size_name' type='button' style='text-decoration:none; color:black;' class='btn btn-block'>$size_name</a></td>";
$i++;
}
} // End of while loop.
?>
</tr>
</tbody>
</table>
</div> <!-- table-responsive end -->
<!-- </form> you can remove this FORM tag if you want -->
How to add the total cost of the purchase items in my table?
I want to add another row , where in the sales total , of the user who bought the specific items to the supplier.
sales_detail table.
sales table.
Sample photo of where i want to add the total price
This would be a big help , thank you guys!
This is my php file.
<h1 class="page-header">Product Sales Report</h1></center>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<center>
<form action="total_sales.php" method="post">
From: <input type="text" class="datepicker" placeholder="E.G.(2018-01-14)" name="dayfrom" required pattern="[0-9]{4}+[0-9]+[0-9]"> To: <input type="text" class="datepicker" placeholder="E.G.(2018-02-11)" name="dayto" required pattern="[0-9]{4}+[0-9]+[0-9]">
<input type="submit" value="Show Sales" name="salesbtn" ></form></center>
<table width="100%" class="table table-striped table-bordered table-hover" id="prodTable">
<thead>
<tr>
<th class="hidden"></th>
<th>Purchase Date</th>
<th>Customer</th>
<th>Product Name</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<?php
$sq=mysqli_query($conn,"select * from sales_detail left join product on product.productid=sales_detail.productid left join sales on sales.salesid=sales_detail.salesid left join customer on sales.userid=customer.userid where product.supplierid='".$_SESSION['id']."' order by sales.sales_date desc");;
while($sqrow=mysqli_fetch_array($sq)){
?>
<tr>
<td class="hidden"></td>
<td><?php echo date('M d, Y h:i A',strtotime($sqrow['sales_date'])); ?></td>
<td><?php echo $sqrow['customer_name']; ?></td>
<td><?php echo $sqrow['product_name']; ?></td>
<td><?php echo $sqrow['sales_qty']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
I added a conditional statement inside the while loop to output the sales total for a user of specific products.
Updated Code:
<h1 class="page-header">Product Sales Report</h1></center>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<center>
<form action="total_sales.php" method="post">
From: <input type="text" class="datepicker" placeholder="E.G.(2018-01-14)" name="dayfrom" required pattern="[0-9]{4}+[0-9]+[0-9]"> To: <input type="text" class="datepicker" placeholder="E.G.(2018-02-11)" name="dayto" required pattern="[0-9]{4}+[0-9]+[0-9]">
<input type="submit" value="Show Sales" name="salesbtn" ></form></center>
<table width="100%" class="table table-striped table-bordered table-hover" id="prodTable">
<thead>
<tr>
<th class="hidden"></th>
<th>Purchase Date</th>
<th>Customer</th>
<th>Product Name</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<?php
$sales_total_id = array();
$sq=mysqli_query($conn,"select * from sales_detail left join product on product.productid=sales_detail.productid left join sales on sales.salesid=sales_detail.salesid left join customer on sales.userid=customer.userid where product.supplierid='".$_SESSION['id']."' order by sales.sales_date desc");
while($sqrow=mysqli_fetch_array($sq)){
if( !isset( $sales_total_id[$sqrow['salesid']] ) ) {
$sales_total_id[$sqrow['salesid']] = TRUE;
?>
<tr>
<td colspan="5" align="center"><strong>Sales Total: <?php echo $sqrow['sales_total']; ?></strong></td>
</tr>
<?php
}
?>
<tr>
<td class="hidden"></td>
<td><?php echo date('M d, Y h:i A',strtotime($sqrow['sales_date'])); ?></td>
<td><?php echo $sqrow['customer_name']; ?></td>
<td><?php echo $sqrow['product_name']; ?></td>
<td><?php echo $sqrow['sales_qty']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
how do I get data value when I echo data inside HTML tag?
$database = new Database();
$db = $database->getConnection();
$query = "SELECT
po.no_po,
barang.nama_barang,
klien.nama_klien,
po.tgl_po,
po.qty,
barang.harga_jual,
po.status_po,
po.keterangan,
surat_pengantar.tgl_kirim,
gudang.nama_gudang,
barang.harga_jual * po.qty AS total_harga
FROM
public.po,
public.barang,
public.klien,
public.good_receipt,
public.gudang,
public.surat_pengantar
WHERE
po.no_po = ?
po.id_barang = barang.id_barang AND
po.id_klien = klien.id_klien AND
po.no_po = surat_pengantar.no_po AND
po.no_po = good_receipt.no_po AND
gudang.id_gudang = good_receipt.id_gudang";
$stmt = $db->prepare( $query );
$stmt->bindParam(1,$no_po);
$stmt->execute();
?>
<body>
<?php
$no=1;
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$no_po = $row['no_po'];
$nama_barang = $row['nama_barang'];
$nama_klien = $row['nama_klien'];
$tgl_po = $row['tgl_po'];
$harga_jual = $row['harga_jual'];
$qty = $row['qty'];
$total_harga = $row['total_harga'];
$status_po = $row['status_po'];
$keterangan = $row['keterangan'];
$nama_gudang = $row['nama_gudang'];
$tgl_po = $row['tgl_po']; */
$no++;
?>
<div class="container">
<div class="row">
<div class="col-xs-6">
<h1>
<a href="https://twitter.com/tahirtaous">
<img src="YSU.png">
Logo here
</a>
</h1>
</div>
<div class="col-xs-6 text-right">
<h1>Purchase Order</h1>
<h1><small><?php echo $no_po;?></small></h1>
</div>
</div>
<div class="row">
<div class="col-xs-5">
<div class="panel panel-default">
<div class="panel-heading">
<h4>From: Your Name</h4>
</div>
<div class="panel-body">
<p>
Address <br>
details <br>
more <br>
</p>
</div>
</div>
</div>
<div class="col-xs-5 col-xs-offset-2 text-right">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Detail Invoice</h4>
</div>
<div class="panel-body">
<table border="0">
<tr>
<td>Tanggal PO</td>
<td>:</td>
<td><?php echo $tgl_po;?></td>
</tr>
<tr>
<td>Gudang</td>
<td>:</td>
<td><?php echo $nama_gudang?></td>
</tr>
<tr>
<td>Nama Pelanggan</td>
<td>:</td>
<td><?php echo $nama_klien?></td>
</tr>
<tr>
<td>Status Purchase Order</td>
<td>:</td>
<td><?php echo $status_po?></td>
</tr>
<tr>
<td>Tanggal Kirim</td>
<td>:</td>
<td><?php echo $tgl_kirim?></td>
</tr>
<tr>
<td>Mata Uang</td>
<td>:</td>
<td>IDR(Rp)</td>
</tr>
<tr>
<td>Term Pembayaran</td>
<td>:</td>
<td>30 hari</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<!-- / end client details section -->
<table class="table table-bordered">
<thead>
<tr>
<th>
<h4>No.item</h4>
</th>
<th>
<h4>Nama barang</h4>
</th>
<th>
<h4>Quantity</h4>
</th>
<th>
<h4>Price</h4>
</th>
<th>
<h4>Keterangan</h4>
</th>
<th>
<h4>Sub Total</h4>
</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $no?></td>
<td><?php echo $nama_barang?></td>
<td><?php echo $qty?></td>
<td class='text-right'><?php echo $harga_jual?></td>
<td class='text-right'><?php echo $keterangan?></td>
<td class='text-right'><?php echo $total_harga?></td>
</tr>
</tbody>
</table>
<div class="row text-right">
<div class="col-xs-2 col-xs-offset-8">
<p>
<strong>
Total : <br>
</strong>
</p>
</div>
<div class="col-xs-2">
<strong>
Rp<?php echo $total_harga?> <br>
</strong>
</div>
</div>
</div>
</body>
</html>
If I remove no_po = :no_po from my query, the result just get the value from one no_po, meanwhile I want the result exist based on no_po.
I declared variable but echo data inside tag HTML doesn't works. The result should get value based on no_po.
Could anyone help me to fix this?
You might want to look into a LEFT JOIN somewhere. What's could be happening is that with all the joins you are using implicitly, the row which you are looking for that does exist, is already being ruled out by the joins. Implicit joins are inner joins and inner joins require all tables to be present with the matching values. So if all the tables are able to join except for your last one 'surat_pengantar', it will nullify the result from the first table that matched on no_po. This is because your condition of po.no_po = surat_pengantar.no_po is false.