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>
Related
I have a table which contain two buttons, one is for uploading a file and the other one is for giving score. What I want to do is to give a condition for the second button which is the scoring button, whereby it can't be clicked (disabled) if there is no file uploaded. How can I achieve this?
Here is what my table looks like:
And here is my AdminController for the table
public function showpekerjaanppk(){
if(Auth::user()->status=='super'){
$pekerjaan = Pekerjaan::with('penyedia','user')->paginate();
return view('admin.showpekerjaan', compact('pekerjaan'));
}else{
$pekerjaan = Auth::user()->pekerjaans;
return view('admin.showpekerjaan', compact('pekerjaan'));
}
//return view('admin.showpekerjaan', compact('penyedia','pekerjaan','totalAvg'));
}
And here is my blade file for the table
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
#if (Auth::user()->status=='super')
<h3 class="card-title"><b>{{$penyedia->nama}}</b></h3> <br>
<h3 class="card-title">Nilai Total: <b>{{$totalAvg}}</b></h3>
#else
<h3 class="card-title"><b></b></h3> <br>
<h3 class="card-title"></b></h3>
#endif
<!-- /.card-header -->
<div class="card-body table-responsive">
<table id="tabelpekerjaan" class="table table-bordered">
<thead>
<tr>
<th style="width: 10px" rowspan="2">No.</th>
<th rowspan="2">Tanggal</th>
<th rowspan="2">Paket Pekerjaan</th>
<th rowspan="2">Nama Perusahaan</th>
<th rowspan="2">Lokasi Pekerjaan</th>
<th rowspan="2">PPK</th>
<th rowspan="2">Nilai Kontrak</th>
<th rowspan="2">Nilai</th>
<th rowspan="2">BAHP</th>
<th colspan="2">Aksi</th>
</tr>
<tr>
<td>BAHP</td>
<td>Nilai</td>
</tr>
</thead>
<tbody>
#php $no = 1; /*$totalNilai = 0.0;*/ #endphp
#foreach ($pekerjaan as $pekerjaans)
<tr>
<td>{{$no++}}</td>
<td>{{$pekerjaans->tanggal}}</td>
<td>{{$pekerjaans->pekerjaan}}</td>
<td>{{$pekerjaans->penyedia->nama}}</td>
<td>{{$pekerjaans->lokasi}}</td>
<td>{{$pekerjaans->user->name}}</td>
<td>Rp. {{number_format($pekerjaans->nilai_kontrak,0,',',',')}}</td>
#php
$pekerjaans->nilai_total = $pekerjaans->nilai_1 + $pekerjaans->nilai_2 + $pekerjaans->nilai_3 + $pekerjaans->nilai_4;
#endphp
<td>{{$pekerjaans->nilai_total}}</td>
<td>{{$pekerjaans->bahp}}</td>
<td>
Upload
</td>
<td>
Penilaian //disabled untill file uploaded
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<!-- /.card-body -->
</div>
<!-- /.card -->
#if (Auth::user()->status=='super')
<div class="card-footer">
Kembali
</div>
#endif
</div>
</section>
Thank you in advance.
#if(isset($pekerjaans->yourFileCulmnName))
<td>
Penilaian //disabled untill file uploaded
</td>
#endif
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…
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 -->
I have a difficulty to display an item of a student based on the student_name. Previously I was able to display an item based on student_username but not using student_name. but now I want to use student_name to display the item which from student_name. I attached together with my code part.
<div class="row">
<!-- Welcome -->
<div class="col-lg-12">
<div class="alert alert-info">
<?php
include("connection.php");
$username=$_SESSION['username'];
$sql=mysql_query("SELECT student_name FROM register WHERE student_username='$username'");
$ee=mysql_fetch_array($sql);
?>
<i class="fa fa-folder-open"></i><b> Hello ! </b>Welcome Back <b><?php echo $ee['student_name']; ?> </b>
</div>
</div>
<!--end Welcome -->
</div>
<div class="row">
<div class="col-lg-12">
<div class="table table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>S.no</th>
<th>Parcel Number</th>
<th>Date Recieved</th>
<th>Date of Collected</th>
<th>Recieved Time</th>
<th>Collect Time</th>
<th>Status</th>
<th>Sent By</th>
<th>Sent To</th>
</tr>
</thead>
<?php
include("connection.php");
$sql1=mysql_query("SELECT * FROM add_parcel WHERE send_to='$username'");
$i=1;
while($row=mysql_fetch_array($sql1)){
echo '<tr class="record"><td>'.$i++.'</td><td>'.$row['date_recieve'].'</td><td>'.$row['date_collect'].'</td><td>'.$row['recieve_time'].'</td><td>'.$row['collect_time'].'</td><td>'.$row['status'].'</td><td>'.$row['sender_name'].'</td><td>'.$row['send_to'].'</td></tr>';
}
?>
add_parcel table = parcel_id,parcel_num,date_recieve,date_collect,recieve_time,collect_time,status,sender_name,send_to
register table = student_id,student_username,student_name,student_address,student_age,student_icenumber, student_email,student_phone,password
Try this code instead:
<div class="row">
<!-- Welcome -->
<div class="col-lg-12">
<div class="alert alert-info">
<?php
include("connection.php");
$username=$_SESSION['username'];
$student_name=$_SESSION['student_name'];
$sql=mysql_query("SELECT student_name FROM register WHERE student_name='$student_name'");
$ee=mysql_fetch_array($sql);
?>
<i class="fa fa-folder-open"></i><b> Hello ! </b>Welcome Back <b><?php echo $ee['student_name']; ?> </b>
</div>
</div>
<!--end Welcome -->
</div>
<div class="row">
<div class="col-lg-12">
<div class="table table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>S.no</th>
<th>Parcel Number</th>
<th>Date Recieved</th>
<th>Date of Collected</th>
<th>Recieved Time</th>
<th>Collect Time</th>
<th>Status</th>
<th>Sent By</th>
<th>Sent To</th>
</tr>
</thead>
<?php
include("connection.php");
$sql1=mysql_query("SELECT * FROM add_parcel WHERE send_to='$student_name'");
$i=1;
while($row=mysql_fetch_array($sql1)){
echo '<tr class="record"><td>'.$i++.'</td><td>'.$row['date_recieve'].'</td><td>'.$row['date_collect'].'</td><td>'.$row['recieve_time'].'</td><td>'.$row['collect_time'].'</td><td>'.$row['status'].'</td><td>'.$row['sender_name'].'</td><td>'.$row['send_to'].'</td></tr>';
}
i'm facing fetch problem in my code. the statement couldn't return the value in $row[]. i have declared the variable before, but only one variable could show in the result. here is my code :
<?php
//require_once('function.php');
//session_start();
//if (!is_user()) {
// redirect('signin.php');
//}
$page_title = "Purchase Order";
include_once 'header.php';
$no_po = $_GET['no_po'];
// include database and object files
include_once 'config/database.php';
//$total_harga = $harga_jual * $qty;
// instantiate database and product object
$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
no_po = :no_po AND
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(':no_po',$no_po);
$result = $stmt->execute();
$no_po ;
$nama_barang=null;
$harga_jual=null;
$qty=null;
$nama_klien=null;
$total_harga=null;
$status_po=null;
$tgl_po=null;
$tgl_kirim=null;
$nama_gudang=null;
$keterangan=null;
while($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'];
$qty = $row['qty'];
$harga_jual = number_format($row['harga_jual'],0,",",".");
$status_po = $row['status_po'];
$keterangan = $row['keterangan'];
$tgl_kirim = $row['tgl_kirim'];
$nama_gudang = $row['nama_gudang'];
$total_harga = number_format($row['total_harga'],0,",",".");
}
?>
<body>
<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>
<?php
$no=1;
echo "<tr>";
echo "<td>{$no}</td>";
echo"<td>{$nama_barang}</td>";
echo"<td>{$qty}</td>";
echo"<td class='text-right'>{$harga_jual}</td>";
echo"<td class='text-right'>{$keterangan}</td>";
echo"<td class='text-right'>{$total_harga}</td>";
echo"</tr>";
$no++;
echo"</tbody>";
echo"</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>
</div>
</body>
</html>
please help me to solve this. thanks
You are over-writing the results with each iteration of your while clause:
You want to output the HTML as you process each row from the recordset.
I think you are looking to do something like this though it has been quite a while since I wrote procedural PHP:
<body>
<?php
while($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'];
$qty = $row['qty'];
$harga_jual = number_format($row['harga_jual'],0,",",".");
$status_po = $row['status_po'];
$keterangan = $row['keterangan'];
$tgl_kirim = $row['tgl_kirim'];
$nama_gudang = $row['nama_gudang'];
$total_harga = number_format($row['total_harga'],0,",",".");
?>
<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>
<?php
$no=1;
echo "<tr>";
echo "<td>{$no}</td>";
echo"<td>{$nama_barang}</td>";
echo"<td>{$qty}</td>";
echo"<td class='text-right'>{$harga_jual}</td>";
echo"<td class='text-right'>{$keterangan}</td>";
echo"<td class='text-right'>{$total_harga}</td>";
echo"</tr>";
$no++;
echo"</tbody>";
echo"</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>
</div>
<?
}
?>
</body>
</html>