Postingan lainnya
Algoritma/Cara Filter pakai Option Select di PHP
Hello Dears , Kali ini saya mau tanya mengenai alur atau logikanya atau syukur syukur bisa kasih scriptnya buat filter data pakai option select di DB pakai SQL server . dikantor saya DB nya pakai SQL server jadi tuntutan nih . hehehe .... saya sudah sertakan Scriptnya ya , tapi masih error . mohon penjelasannya ya . saya newbie .
catatan :
Thanks ,
<!doctype html>
<html lang="en">
<head>
<title>Giromix Data Information</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="bootstrap4.1.3/css/bootstrap.min.css" crossorigin="anonymous">
</head>
<body>
<div class="container" >
<h1 align="center">Giromix Information </h1>
<br>
<br>
<br>
<form action="showgiromix2.php" method="POST">
<!-- custom file input date picker -->
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="inputGroupSelect01" style="width: 150px">Start Date</label>
<input type="Date" name="tgl_dari">
<label class="input-group-text" for="inputGroupSelect01" style="width: 150px">End Date</label>
<input type="Date" name="tgl_sampai">
<button class="btn btn-primary" type="submit" value="filter">Show</button>
</div>
</div>
<br> <br>
<!-- custom file input List Machines -->
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="inputGroupSelect01" style="width: 150px;">List Machines</label>
</div>
<select class="custom-select" id="inputGroupSelect01" name="select">
<option selected>Choose...</option>
<option value="TRI1">Extruder</option>
<option value="LIN1">Inner Complex</option>
<option value="TEX1">Textile Calendar</option>
</select>
</div>
</form>
<br>
<br>
<table class="table" >
<thead class="thead-dark">
<tr>
<th scope="col">No</th>
<th scope="col">Plant</th>
<th scope="col">Machines Code</th>
<th scope="col">Calculation Date</th>
<th scope="col">PP Code</th>
<th scope="col">SFC Code Code</th>
<th scope="col">ST Code</th>
<th scope="col">Value 1</th>
<th scope="col">Value 2</th>
<th scope="col">Change Count</th>
<th scope="col">Distinct Count</th>
<th scope="col">Factory</th>
</tr>
</thead>
<?php include 'connection.php'; ?>
<?php
if(isset($_POST['tgl_dari']) && isset($_POST['tgl_sampai'])){
$dari = $_POST['tgl_dari'];
$sampai = $_POST['tgl_sampai'];
?>
<?php
//ambil submit
if (isset($_POST['submit'])) {
if ($_POST['select'] == 'TRI1') {
$sql = "select * from [PCSRepository].[dbo].dc_giromix where PLANT ='ID' and MCH_CODE ='TRI1' and CALC_DATE >= '$dari' and CALC_DATE <= '$sampai' order by CALC_DATE desc";
}
elseif ($_POST['select'] == 'LIN1') {
$sql = "select * from [PCSRepository].[dbo].dc_giromix where PLANT ='ID' and MCH_CODE ='LIN1' and CALC_DATE >= '$dari' and CALC_DATE <= '$sampai' order by CALC_DATE desc" ;
}
elseif ($_POST['select'] == 'TEX1') {
$sql = "select * from [PCSRepository].[dbo].dc_giromix where PLANT ='ID' and MCH_CODE ='TEX1' and CALC_DATE >= '$dari' and CALC_DATE <= '$sampai' order by CALC_DATE desc" ;
}
else {
echo "Please Select the machines List ";
}
}
?>
<?php
// mengambil data dari database
$data = odbc_exec($koneksi,$sql);
$no = 1;
// mengubah data ke array dan menampilkannya dengan perulangan while
while($d=odbc_next_result($data)){
?>
<tbody>
<tr>
<th scope="row"><?php echo $no++; ?></th>
<td><?php echo $d['PLANT']; ?></td>
<td><?php echo $d['MCH_CODE']; ?></td>
<td><?php echo $d['CALC_DATE']; ?></td>
<td><?php echo $d['PP_CODE']; ?></td>
<td><?php echo $d['SFC_CODE']; ?></td>
<td><?php echo $d['ST_CODE']; ?></td>
<td><?php echo ((float)$d['VAL1']); ?></td>
<td><?php echo ((float)$d['VAL2']); ?></td>
<td><?php echo ((float)$d['CHANGE_COUNT']); ?></td>
<td><?php echo $d['DISTINCT_COUNT']; ?></td>
<td><?php echo $d['FACTORY']; ?></td>
<!-- //var_dump($d['VAL1']); -->
</tr>
</tbody>
<?php }} ?>
</table>
<br> <a href='export.php'> Cetak </a>
</div>
</body>
</html>
ini tampilan errornya ..
4 Jawaban:
coba tombol ini kasih name juga <pre> <button class="btn btn-primary" type="submit" value="filter">Show</button> </pre> ubah jadi <pre> <button class="btn btn-primary" type="submit" name="submit" value="filter">Show</button> </pre>
Thanks banget mas , sudah berhasil .
ini ss nya <img src='https://i.imgur.com/eGryVR7.png'>
tapi saya mau tanya lagi , kalo mau kasih notifikasi salah satu formnya belum di isi gimana ya ? misal tidak input tanggal atau tanggalnya salah kelebihan terus nanti pas di submit muncul pemberitahuan . dan menghide warning atau notice .
berikut ss nya .
<img src='https://i.imgur.com/QQpcHIz.png'>
berikut kodenya finalnya .
<pre>
<!doctype html> <html lang="en"> <head> <title>Giromix Data Information</title> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
&lt;!-- Bootstrap CSS --&gt;
&lt;link rel="stylesheet" href="bootstrap4.1.3/css/bootstrap.min.css" crossorigin="anonymous"&gt;
</head>
<body> <div class="container" >
<form action="showgiromix2.php" method="POST">
&lt;!-- custom file input date picker --&gt;
&lt;div class="input-group mb-3"&gt;
&lt;div class="input-group-prepend"&gt;
&lt;label class="input-group-text" for="inputGroupSelect01" style="width: 150px"&gt;Start Date&lt;/label&gt;
&lt;input type="Date" name="tgl_dari"&gt;
&lt;label class="input-group-text" for="inputGroupSelect01" style="width: 150px"&gt;End Date&lt;/label&gt;
&lt;input type="Date" name="tgl_sampai"&gt;
&lt;button class="btn btn-primary" type="submit" name="submit" value="filter"&gt;Show&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
<br> <br>
<!-- custom file input List Machines -->
&lt;div class="input-group mb-3"&gt;
&lt;div class="input-group-prepend"&gt;
&lt;label class="input-group-text" for="inputGroupSelect01" style="width: 150px;"&gt;List Machines&lt;/label&gt;
&lt;/div&gt;
&lt;select class="custom-select" id="inputGroupSelect01" name="select"&gt;
&lt;option selected&gt;Choose...&lt;/option&gt;
&lt;option value="TRI1"&gt;Extruder&lt;/option&gt;
&lt;option value="LIN1"&gt;Inner Complex&lt;/option&gt;
&lt;option value="TEX1"&gt;Textile Calendar&lt;/option&gt;
&lt;/select&gt;
&lt;/div&gt;
</form>
<br> <br> <table class="table" > <thead class="thead-dark"> <tr> <th scope="col">No</th> <th scope="col">Plant</th> <th scope="col">Machines Code</th> <th scope="col">Calculation Date</th> <th scope="col">PP Code</th> <th scope="col">SFC Code Code</th> <th scope="col">ST Code</th> <th scope="col">Value 1</th> <th scope="col">Value 2</th> <th scope="col">Change Count</th> <th scope="col">Distinct Count</th> <th scope="col">Factory</th>
&lt;/tr&gt;
&lt;/thead&gt;
<?php include 'connection.php'; ?>
<?php if(isset($_POST['tgl_dari']) && isset($_POST['tgl_sampai'])){
$dari = $_POST['tgl_dari'];
$sampai = $_POST['tgl_sampai'];
?>
<?php //ambil submit if (isset($_POST['submit'])) { if ($_POST['select'] == 'TRI1') { $sql = "select * from [PCSRepository].[dbo].dc_giromix where PLANT ='ID' and MCH_CODE ='TRI1' and CALC_DATE >= '$dari' and CALC_DATE <= '$sampai' order by CALC_DATE desc"; }
elseif ($_POST['select'] == 'LIN1') {
$sql = "select * from [PCSRepository].[dbo].dc_giromix where PLANT ='ID' and MCH_CODE ='LIN1' and CALC_DATE &gt;= '$dari' and CALC_DATE &lt;= '$sampai' order by CALC_DATE desc" ;
}
elseif ($_POST['select'] == 'TEX1') {
$sql = "select * from [PCSRepository].[dbo].dc_giromix where PLANT ='ID' and MCH_CODE ='TEX1' and CALC_DATE &gt;= '$dari' and CALC_DATE &lt;= '$sampai' order by CALC_DATE desc" ;
}
else {
echo "Please Select the machines List ";
}
} ?>
&lt;?php
// mengambil data dari database
$data = odbc_exec($koneksi,$sql);
$no = 1;
// mengubah data ke array dan menampilkannya dengan perulangan while while($d=odbc_fetch_array($data)){
?> <tbody> <tr> <th scope="row"><?php echo $no++; ?></th> <td><?php echo $d['PLANT']; ?></td> <td><?php echo $d['MCH_CODE']; ?></td> <td><?php echo $d['CALC_DATE']; ?></td> <td><?php echo $d['PP_CODE']; ?></td> <td><?php echo $d['SFC_CODE']; ?></td> <td><?php echo $d['ST_CODE']; ?></td> <td><?php echo ((float)$d['VAL1']); ?></td> <td><?php echo ((float)$d['VAL2']); ?></td> <td><?php echo ((float)$d['CHANGE_COUNT']); ?></td> <td><?php echo $d['DISTINCT_COUNT']; ?></td> <td><?php echo $d['FACTORY']; ?></td>
&lt;!-- //var_dump($d['VAL1']); --&gt;
&lt;/tr&gt;
</tbody> <?php }} ?> </table> <br> <a href='export.php'> Cetak </a> </div> </body> </html>
</pre>
Jawaban Terpilih
<pre> tapi saya mau tanya lagi , kalo mau kasih notifikasi salah satu formnya belum di isi gimana ya ? misal tidak input tanggal atau tanggalnya salah kelebihan terus nanti pas di submit muncul pemberitahuan .</pre> ya tinggal kasih pengecekan, tambahkan else dari <pre> if(isset($_POST['tgl_dari']) && isset($_POST['tgl_sampai'])){}else {echo "tanggal harus diisi"} </pre> <pre> menghide warning atau notice . </pre>tambahkan sebelum <!doctype html> <pre> <?php error_reporting(0) ?> </pre>