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>
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 trying to populate modals with data from mysql database, relating to the card that the user clicks on. The cards are generated by while loop - example below.
Right now my modal only shows the data relating to the first row of the database, no matter which card you click on. What is the easiest why to tie the card data to the modal?
<?php
$result = $conn->query($query);
if (!$result){
echo $conn->error;
}else{
while($row = $result->fetch_assoc()){
if ($row["size"]=='XLarge'){
echo "<div class='col-4 col padding-small'>
<div class='card' style='width: 100%'>
<div class='card-body'>
<h4 class='mybreed'>{$row["breed"]}</h4>
<h5 class='card-subtitle'>Category: {$row["category"]}</h5>
<div class='row flex-spaces child-borders'>
<label class='paper-btn margin' for='modal-2' onclick='modal-2'>Learn about me!</label>
</div>
<img class='image-bottom' style='width: 100%' src='{$row["image"]}'
alt='No image available'>
</div>
</div>
</div>";
echo "<input class='modal-state' id='modal-2' type='checkbox'>
<div class='modal'>
<label class='modal-bg' for='modal-2'></label>
<div class='modal-body'>
<label class='btn-close' for='modal-2'>X</label>
<h4 class='modal-title'>Factfile: {$row["breed"]}</h4>
<p class='modal-text'>
<table>
<tbody>
<tr>
<td>Category:</td>
<td>{$row["category"]}</td>
</tr>
<tr>
<td>Intelligence:</td>
<td>{$row["intelligence_category"]}</td>
</tr>
<tr>
<td>Intelligence Rank:</td>
<td># {$row["intelligence_rank"]}</td>
</tr>
<tr>
<td>Average Lifespan:</td>
<td>{$row["average_lifespan"]} years</td>
</tr>
<tr>
<td>Average Shoulder Height & Weight:</td>
<td>{$row["shoulder_height_cm"]} cm / {$row["weight_kg"]} kg</td>
</tr>
<tr>
<td>Suitability for children:</td>
<td>{$row["suitability_for_children"]}</td>
</tr>
<tr>
<td>Known Health Problems:</td>
<td>{$row["genetic_diseases"]}</td>
</tr>
<tr>
<td>Cost of Ownership:</td>
<td>{$row["price_bracket"]}</td>
</tr>
</tbody>
</table>
</p>
</div>
</div>";
}
}
}
$result->close();
?>
I have popup it works normal i need to use method post to get my value from the input balise but the problem is when i do form the popup window displays in just a second then hide again and I need to click two time becausethe first time i got just the last result
<div class="List_modify">
<table class="list">
<thead class="topBar">
<tr>
<th>Prenom</th>
<th>Nom</th>
<th>CIN</th>
<th>Emails</th>
<th>Références</th>
<th>Photos</th>
<th>Niveau</th>
<th class="button_editer" style="vertical-align:middle"><span>Editer</span></th>
</tr>
</thead>
<?php $requet = "select * from Etudiants";
$resultat = mysqli_query($connecte, $requet);
while ($r = mysqli_fetch_array($resultat)) {
?>
<tbody class="container">
<tr>
<td>
<?php echo $r['Prenom']; ?>
</td>
<td>
<?php echo $r['Nom']; ?>
</td>
<td>
<?php echo $r['CIN']; ?>
</td>
<td>
<?php echo $r['Emails']; ?>
</td>
<td>
<?php echo $r['Matricule']; ?>
</td>
<td> <img src="image/<?php echo $r['Photo']; ?> " style="width: 150px; height:150px;"></td>
<td>
<?php echo $r['Niveau']; ?> </td>
<td>
<form method="POST" action="">
<input type="hidden" name="id" value="<?php echo $r['Id_Etudiant']; ?>">
<button class=" button" onclick="show()" style="vertical-align:middle" type="submit" name="submit"><span>Editer<i class=" fas fa-user-edit"></i></span>
</button>
</form>
</td>
</tr>
</tbody>
<?php } ?>
</table>
</div>
<div class="background_page_modify" id="page_modify" onclick="hide()">
<div class="page_etudiant" onclick="event.stopPropagation()">
<div class="closebtn" id="closebtn" onclick="hide()">
<div class="circle"> +</div>
</div>
<div class="etudiant_box">
<?php
if (isset($_REQUEST['submit'])) {
$checkid = $_REQUEST['id'];
echo $checkid;
}
?>
</div>
</div>
</div>
I have a table reading out a few columns of a db, with an edit button in each row. All I am trying to do is, when the edit button is clicked, that row is displayed with all of its columns in another page. Any help would be great. I know it's simple, but I can get it to work. I am able to navigate to the next page, but not sure how to carry the id of the specific row and read that out. Thanks.
index. php
<form id="mainform" action="editFunding2.php">
<div class='row'>
<div class='col-12'>
<div class='table table-responsive'>
<table class='table table-striped table-bordered datatable active' id='grantTable'>
<thead>
<tr>
<th>FP ID</th>
<th>Short Title</th>
<th>PI</th>
<th>Department</th>
<th>Funding Type</th>
<th>Change Funding Type</th>
</tr>
</thead>
<tbody>
<?php
//Foreach loop iterates through each column of $getallrows function
foreach($allRows as $rowID => $rowInfo){ ?>
<tr>
<td><?php echo $rowInfo['fpID'];?></td>
<td><?php echo $rowInfo['shortTitle'];?></td>
<td><?php echo $rowInfo['PI'];?></td>
<td><?php echo $rowInfo['Department'];?></td>
<td><?php echo $rowInfo['fundingType'];?></td>
<!--Create dynamic id -->
<?php $rdDrop = "ddgrantType_".$rowInfo['fpID'];?>
<td>
<button type="submit" class="btn btn-danger" name="action" value='Change Funding Type'>Change Funding</button>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</form>
My editFunding2.php page
<div class='row'>
<div class='col-12'>
<div class='table table-responsive'>
<table class='table table-striped table-bordered datatable active' id='grantTable'>
<thead>
<tr>
<th>FP ID</th>
<th>Short Title</th>
<th>PI</th>
<th>Department</th>
<th>Division</th>
<th>Sponsor Name</th>
<th>Project Start</th>
<th>Project End</th>
<th>Funding Type</th>
<th>Yes/No</th>
<th>Proper Type If No</th>
<!-- <th>Exclusions</th>
<th>FP Durtation</th> -->
<th>Comment</th>
</tr>
</thead>
<tbody>
<?php
session_start();
$editRow = $_REQUEST['fpID'];
$mssql = mysqli_query("SELECT * FROM spacing.METADATA_WEBFORM WHERE FUNDING_PROPOSAL_ID = $fpID' ") or die (mysqli_error());
while($rowInfo = mysqli_fetch_array($mssql)) {
?>
<tr>
<td><?php echo $rowInfo['fpID'];?></td>
<td><?php echo $rowInfo['shortTitle'];?></td>
<td><?php echo $rowInfo['PI'];?></td>
<td><?php echo $rowInfo['Department'];?></td>
<td><?php echo $rowInfo['Division'];?></td>
<td><?php echo $rowInfo['sponsorName'];?></td>
<td><?php echo $rowInfo['Date_Project_Start']->format('Y-m-d');?></td>
<td><?php echo $rowInfo['Date_Project_End']->format('Y-m-d');?></td>
<td><?php echo $rowInfo['fundingType'];?></td>
<?php } ?>
<!--Create dynamic id -->
<?php $rdDrop = "ddgrantType_".$rowInfo['fpID'];?>
<td>
<div class="form-check">
<label class="form-check-label">
<input type="radio" class='form-check-input' name="rdGrant[<?php echo $rowInfo['fpID'];?>]" value="Yes" id="rdYes" onclick="disable('<?php echo $rdDrop;?>')" checked/> Yes
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input class='form-check-input' type="radio" name="rdGrant[<?php echo $rowInfo['fpID'];?>]" value="No" id="rdNo" onclick="enable('<?php echo $rdDrop;?>')"/> No
</label>
</div>
</td>
<td>
<div class="dropdown">
<select class='form-control' name="ddgrantGroup[<?php echo $rowInfo['fpID'];?>]" id="<?php echo $rdDrop;?>" disabled>
<option value=''>Select Proper Funding Type</option>
<option value="Corporate Sponsor">Corporate Sponsor</option>
<option value="Federal">Federal</option>
<option value="Foundation Selected">Foundation Selected</option>
<option value="Internally Funded">Internally Funded</option>
<option value="State/Local">State/Local</option>
</select>
</div>
</td>
<td>
<div class="comment">
<textarea class="form-control" aria-label="With textarea" name="grantComment[<?php echo $rowInfo['fpID'];?>]" id="grantComment" placeholder="Comments"></textarea>
</div>
</td>
</tr>
</tbody>
</div>
</div>
</div>
<div class='row'>
<div class='col-12 text-right'>
<button type="submit" class="btn btn-secondary formsubmitbttn" name="action" value='save'>Save</button>
<button type="submit" class="btn btn-primary formsubmitbttn" name="action" value='complete'>Complete and Save</button>
</div>
</div>
</div>
Change your button to a
My Link to xx
In editFunding2.php :
$editRow = $_GET['id'];
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.