I want some additional function on my program that will filter the data base on the month selected
<div class="content-loader">
<form method="post" action="index.php"> //select month
<select name="month" id="month">
<option></option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option> //date format on my database yyyy-mm-dd
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<input type="submit" value="submit" name="submit"/>
</form>
<table cellspacing="0" width="100%" id="example" class="table table- striped table-hover table-responsive">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Check In Date</th> //table head
<th>Check Out Date</th>
<th>Room Rate</th>
<th>Reservation Fee</th>
<th>Date Paid</th>
<th>Mode of Paymnet</th>
<th>Status</th>
<th>edit</th>
<th>delete</th>
</tr>
</thead>
<tbody>
so I modified it and I'm getting this error
Notice: Array to string conversion in
Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Array' in
'where clause'' in Stack trace: #0 PDOStatement->execute() #1 {main}
thrown in
<?php
require_once 'dbconfig.php';
$stmt = $db_con->prepare("SELECT * FROM tblguest WHERE MONTH(checkin) =".['month']." ");
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['fname']; ?></td>
<td><?php echo $row['lname']; ?></td>
<td><?php echo $row['checkin']; ?></td>
<td><?php echo $row['checkout']; ?></td>
<td><?php echo $row['rrate']; ?></td> //data
<td><?php echo $row['reservefee']; ?></td>
<td><?php echo $row['datepaid']; ?></td>
<td><?php echo $row['modepayment']; ?></td>
<td><?php echo $row['stats']; ?></td>
<td align="center">
<a id="<?php echo $row['fname']." ".$row['lname']; ?>" class="edit-link" href="#" title="Edit">
<img src="edit.png" width="20px" />
</a></td>
<td align="center"><a id="<?php echo $row['fname']." ".$row['lname']; ?>" class="delete-link" href="#" title="Delete">
<img src="delete.png" width="20px" />
</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
AS mentioned in Comments try this
"SELECT * FROM tblguest WHERE MONTH(checkin) =".$_POST['month'];
You should write this. This might solve your problem
$stmt = $db_con->prepare("SELECT * FROM tblguest WHERE MONTH(checkin) = '".$_POST['month']."' ");
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['fname']; ?></td>
<td><?php echo $row['lname']; ?></td>
<td><?php echo $row['checkin']; ?></td>
<td><?php echo $row['checkout']; ?></td>
<td><?php echo $row['rrate']; ?></td> //data
<td><?php echo $row['reservefee']; ?></td>
<td><?php echo $row['datepaid']; ?></td>
<td><?php echo $row['modepayment']; ?></td>
<td><?php echo $row['stats']; ?></td>
<td align="center">
<a id="<?php echo $row['fname']." ".$row['lname']; ?>" class="edit-link" href="#" title="Edit">
<img src="edit.png" width="20px" />
</a></td>
<td align="center"><a id="<?php echo $row['fname']." ".$row['lname']; ?>" class="delete-link" href="#" title="Delete">
<img src="delete.png" width="20px" />
</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
Related
In this code, I have 2 dropdowns in the table (one is the options from MySQL and I checked the condition for options) and I want to pass their values for each row to the next page when I push the button "call" in that row.
So, how can I do this?
<table class="table-info">
<thead>
<tr>
<th>HN number</th>
<th>name</th>
<th>surname</th>
<th>gender</th>
<th>date of birth</th>
<th>claim</th>
<th>department</th>
<th>unit</th>
<th>tel</th>
<th>time</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_assoc($result)) { ?>
<tr>
<td><?php echo $row["hn"] ?></td>
<td><?php echo $row["first_name"] ?></td>
<td><?php echo $row["last_name"] ?></td>
<td><?php echo $row["gender"] ?></td>
<td><?php echo $row["DOB"] ?></td>
<td><?php echo $row["claim"] ?></td>
<td><?php echo $row["dept"] ?></td>
<td><?php echo $row["unit"] ?></td>
<td><?php echo $row["tel"] ?></td>
<td><?php echo $row["q_time"] ?></td>
<td>
<div action = "manage_db.php" method="post">
<select class="select" name="doc_drop" <?= ( $row["doc"] == 'general' ? '' : 'disabled' ) ?> require>
<option selected disabled>doctor</option>
<?php foreach($result2 as $doc_select){?>
<option value="<?php echo $doc_selectp["doc"];?>"
<?= ( trim( $row["doc"] ) == $doc_select["doc"] ? 'selected' : '' ) ?> >
<?php echo $doc_select["doc"];?>
</option>
<?php } ?>
</select>
<select class="select" name="room" require>
<option selected disabled> room </option>
<option value="1">room 1</option>
<option value="2">room 2</option>
<option value="3">room 3</option>
<option value="4">room 4</option>
<option value="5">room 5</option>
</select>
<a href="manage_db.php?hn_patient=<?php echo $row["hn"];?>" class = btn-call >call</a>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
My website
I've a view to displaying some data from database to my php program, but the data cannot be displayed when I running it?
this is my view from phpmyadmin look like
(select `m`.`id_mutasi` AS `id_mutasi`,`m`.`tgl_mutasi` AS `tgl_mutasi`,`m`.`kode_barang` AS `kode_barang`,`a`.`nm_barang` AS `nm_barang`,`m`.`ruang_lama` AS `ruang_lama`,`m`.`ruang_baru` AS `ruang_baru`,`u`.`nm_unit` AS `unit_lama`,`m`.`unit_baru` AS `unit_baru`,`i`.`user` AS `user_lama`,`m`.`userbaru` AS `user_baru`,`m`.`jumlah` AS `jumlah`,`m`.`user_posting` AS `user_posting` from ((((((`simaset`.`mutasi` `m` join `simaset`.`inventarisasi` `i` on((`m`.`kode_inventarisasi_baru` = `i`.`kode_inventarisasi`))) join `simaset`.`aset` `a` on((`a`.`kode_barang` = `m`.`kode_barang`))) join `simaset`.`ruangan` `r` on((`r`.`kode_ruangan` = `m`.`ruang_lama`))) join `simaset`.`ruangan` `rb` on((`rb`.`kode_ruangan` = `i`.`kode_ruangan`))) join `simaset`.`unit_kerja` `u` on((`u`.`kode_unit` = `m`.`unit_lama`))) join `simaset`.`unit_kerja` `ub` on((`ub`.`kode_unit` = `i`.`kode_unit`))))
and this is my php code
<table id="table-example" class="table" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<!-- <th>NO</th> -->
<th>ID Mutasi</th>
<th>Tgl Mutasi</th>
<th>Kode Barang</th>
<th>Barang</th>
<th>Dept Lama</th>
<th>Jabatan Lama</th>
<th>Dept Baru</th>
<th>Jabatan Baru</th>
<!-- <th>User Baru</th> -->
<th>Jumlah</th>
<th>User Posting</th>
<!-- <th>User Posting</th> -->
<th>Aksi</th>
</tr>
</thead>
<tbody>
<!-- <?php $no = 1;?> -->
<?php do { ?>
<tr class=gradeX>
<!-- <td><center><?php echo $no++ ?></center></td> -->
<td><center>
<?php echo $row_rs_data['id_mutasi']; ?>
</center></td>
<td><?php echo $row_rs_data['tgl_mutasi']; ?></td>
<td ><?php echo $row_rs_data['kode_barang']; ?></td>
<td ><?php echo $row_rs_data['nm_barang']; ?></td>
<td ><?php echo $row_rs_data['ruanglama']; ?></td>
<td ><?php echo $row_rs_data['unitlama']; ?></td>
<td ><?php echo $row_rs_data['ruangbaru']; ?></td>
<td ><?php echo $row_rs_data['unitbaru']; ?></td>
<!-- <td ><?php echo $row_rs_data['userbaru']; ?></td> -->
<td ><center><?php echo $row_rs_data['jumlah']; ?></center></td>
<td ><?php echo $row_rs_data['user_posting']; ?></td>
<td ><img src="img/icons/packs/silk/16x16/cross.png" width="16" height="16" alt="Hapus" title="Hapus" /></td>
</tr>
<?php
echo "test";
} while ($row_rs_data = mysql_fetch_assoc($rs_data)); ?>
</tbody>
</table>
Replace your <tbody> block. Use while instead of do..while and mysqli instead of mysql mysql has been deprecated.
<tbody>
<?php while ($row_rs_data = mysql_fetch_assoc($rs_data)){ ?>
<tr class=gradeX>
<!-- <td><center><?php echo $no++ ?></center></td> -->
<td><center>
<?php echo $row_rs_data['id_mutasi']; ?>
</center></td>
<td><?php echo $row_rs_data['tgl_mutasi']; ?></td>
<td ><?php echo $row_rs_data['kode_barang']; ?></td>
<td ><?php echo $row_rs_data['nm_barang']; ?></td>
<td ><?php echo $row_rs_data['ruanglama']; ?></td>
<td ><?php echo $row_rs_data['unitlama']; ?></td>
<td ><?php echo $row_rs_data['ruangbaru']; ?></td>
<td ><?php echo $row_rs_data['unitbaru']; ?></td>
<!-- <td ><?php echo $row_rs_data['userbaru']; ?></td> -->
<td ><center><?php echo $row_rs_data['jumlah']; ?></center></td>
<td ><?php echo $row_rs_data['user_posting']; ?></td>
<td ><img src="img/icons/packs/silk/16x16/cross.png" width="16" height="16" alt="Hapus" title="Hapus" /></td>
</tr>
<?php
echo "test";
} ?>
</tbody>
I want to make my dropdown list auto select base on the present month
and show the record on my datatable
<div class="container-fluid">
<h2 class="form-signin-heading">Schedule Management</h2><hr />
<button class="btn btn-info" type="button" id="btn-add"> <span class="glyphicon glyphicon-pencil"></span> Add Schedule</button>
<button class="btn btn-info" type="button" id="btn-view"> <span class="glyphicon glyphicon-eye-open"></span> View Schedule</button>
<hr />
this part is where I select the month and submit(If i pick a month on my drop down ex.Nov it will auto submit its already working) what I want is to select automatically default value base on the present month ex. next month is Dec. everytime I open my website its already selected in Dec.
(isset($_POST["months"])) ? $dropDownVal = $_POST["months"] : $dropDownVal=0;
?>
<div class="content-loader">
<form method="post" action="index.php">
Select a month <select name="months" id="months" onchange ='this.form.submit()'>
<option value="0" <?php if ($dropDownVal==0) echo 'selected'; ?>>--------------</option>
<option value="1" <?php if ($dropDownVal==1) echo 'selected'; ?>>January</option>
<option value="2" <?php if ($dropDownVal==2) echo 'selected'; ?>>February</option>
<option value="3" <?php if ($dropDownVal==3) echo 'selected'; ?>>March</option>
<option value="4" <?php if ($dropDownVal==4) echo 'selected'; ?>>April</option>
<option value="5" <?php if ($dropDownVal==5) echo 'selected'; ?>>May</option>
<option value="6" <?php if ($dropDownVal==6) echo 'selected'; ?>>June</option>
<option value="7" <?php if ($dropDownVal==7) echo 'selected'; ?>>July</option>
<option value="8" <?php if ($dropDownVal==8) echo 'selected'; ?>>August</option>
<option value="9" <?php if ($dropDownVal==9) echo 'selected'; ?>>September</option>
<option value="10"<?php if ($dropDownVal==10) echo 'selected'; ?>>October</option>
<option value="11"<?php if ($dropDownVal==11) echo 'selected';?>>November</option>
<option value="12"<?php if ($dropDownVal==12) echo 'selected';?>>December</option>
</select>
<noscript><input type="submit" value="Submit"></noscript>
</form>
<table cellspacing="0" width="100%" id="example" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>Sched #</th>
<th>First Name</th>
<th>Last Name</th>
<th>Check In Date</th>
<th>Check Out Date</th>
<th>Room Rate</th>
<th>Reservation Fee</th>
<th>Date Paid</th>
<th>Mode of Paymnet</th>
<th>Status</th>
<th>edit</th>
<th>delete</th>
</tr>
</thead>
<tbody>
<?php
require_once 'dbconfig.php';
if(isset($_POST['months'])){ $months = $_POST['months']; }else { $months='';}
$sqladd = mysql_query("SELECT sum(rrate) from tblguest WHERE status = 0 and MONTH(checkin) = '".$months."' ");
while($result = mysql_fetch_assoc($sqladd)){
$stmt = $db_con->prepare("SELECT * FROM tblguest WHERE status = 0 and MONTH(checkin) = '".$months."' ");
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['fname']; ?></td>
<td><?php echo $row['lname']; ?></td>
<td><?php echo $row['checkin']; ?></td>
<td><?php echo $row['checkout']; ?></td>
<td><?php echo $row['rrate']; ?></td>
<td><?php echo $row['reservefee']; ?></td>
<td><?php echo $row['datepaid']; ?></td>
<td><?php echo $row['modepayment']; ?></td>
<td><?php echo $row['stats']; ?></td>
<td align="center">
<a id="<?php echo $row['id']; ?>" class="edit-link" href="#" title="Edit">
<img src="edit.png" width="20px" />
</a></td>
<td align="center"><a id="<?php echo $row['id']; ?>" class="delete-link" href="#" title="Delete">
<img src="delete.png" width="20px" />
</a></td>
</tr>
<?php
}
echo "<b>Total Room Rental Income</b> = " , $result['sum(rrate)'];
}
?>
</tbody>
Try this:
<?php
$currentMonth = date('n');
?>
<select>
<option value="1" <?php if ($currentMonth == 1) echo 'selected'; ?>>January</option>
...
//up to december
</select>
Use this to check on date parameters of PHP.
http://php.net/manual/en/function.date.php
I want to delete multiple rows that are selected in tables when I press Delete button my code is this
index.php
<?php
if(isset($_POST['Delete']))
{
for($i=0;$i<count($checkbox);$i++){
$ids= $checkbox[$i];
$query2="DELETE FROM products WHERE serialid='$ids'";
mysqli_query($conn,$query2);
}
}
$query2="SELECT * FROM products";
$allresult = mysqli_query($conn,$query2);
?>
<form method="POST" action="index.php">
<input type="button" class="btn btn-danger" name="Delete" value="Delete"/>
</form>
<table class="table table-striped table-hover table-responsive" id="inventoryTable">
<thead>
<tr>
<td>Serial ID</td>
<td>Name</td>
<td>Manufacturer</td>
<td>Keys</td>
<td>Description</td>
<td>Category</td>
<td>Block</td>
<td>Floor</td>
<td>Room</td>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_array($allresult)) { ?>
<tr>
<td><input name="checkbox[]" type="checkbox" value="<?php echo $row['serialid']; ?>"></td>
<td><?php echo $row['serialid']?></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['manufacturer'] ?></td>
<td><?php echo $row['licensekeys'] ?></td>
<td><?php echo $row['description'] ?></td>
<td><?php echo $row['categoryname'] ?></td>
<td><?php echo $row['block'] ?></td>
<td><?php echo $row['floor'] ?></td>
<td><?php echo $row['room'] ?></td>
</tr>
<?php }?>
</tbody>
</table>
But whenever I select rows and press delete button nothing happens. Is there anything am I missing?
The usage of form is entirely wrong on your HTML page. The form should appear as how i have done. Input type button is wrong you have to change to submit..
<?php
if(isset($_POST['Delete']))
{
for($i=0;$i<count($_POST['checkbox']);$i++){
$ids= $_POST['checkbox'][$i];
$query2="DELETE FROM products WHERE serialid='".$ids."'";
mysqli_query($conn,$query2);
}
}
$query2="SELECT * FROM products";
$allresult = mysqli_query($conn,$query2);
?>
<form method="POST" action="index.php">
<input type="submit" class="btn btn-danger" name="Delete" value="Delete"/>
<table class="table table-striped table-hover table-responsive" id="inventoryTable">
<thead>
<tr>
<td>Serial ID</td>
<td>Name</td>
<td>Manufacturer</td>
<td>Keys</td>
<td>Description</td>
<td>Category</td>
<td>Block</td>
<td>Floor</td>
<td>Room</td>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_array($allresult)) { ?>
<tr>
<td><input name="checkbox[]" type="checkbox" value="<?php echo $row['serialid']; ?>"></td>
<td><?php echo $row['serialid']?></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['manufacturer'] ?></td>
<td><?php echo $row['licensekeys'] ?></td>
<td><?php echo $row['description'] ?></td>
<td><?php echo $row['categoryname'] ?></td>
<td><?php echo $row['block'] ?></td>
<td><?php echo $row['floor'] ?></td>
<td><?php echo $row['room'] ?></td>
</tr>
<?php }?>
</tbody>
</table>
</form>
Wrap all the details in the <form> element.
Close the form tag end of the table then only you can get the post value.Try like this
<form method="POST" action="index.php">
<input type="button" class="btn btn-danger" name="Delete" value="Delete"/>
<table class="table table-striped table-hover table-responsive" id="inventoryTable">
<thead>
<tr>
<td>Serial ID</td>
<td>Name</td>
<td>Manufacturer</td>
<td>Keys</td>
<td>Description</td>
<td>Category</td>
<td>Block</td>
<td>Floor</td>
<td>Room</td>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_array($allresult)) { ?>
<tr>
<td><input name="checkbox[]" type="checkbox" value="<?php echo $row['serialid']; ?>"></td>
<td><?php echo $row['serialid']?></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['manufacturer'] ?></td>
<td><?php echo $row['licensekeys'] ?></td>
<td><?php echo $row['description'] ?></td>
<td><?php echo $row['categoryname'] ?></td>
<td><?php echo $row['block'] ?></td>
<td><?php echo $row['floor'] ?></td>
<td><?php echo $row['room'] ?></td>
</tr>
<?php }?>
</tbody>
</table>
</form>
<?php
if(isset($_POST['Delete']))
{
$delete = $_POST['checkbox'];
foreach ($delete as $ids) {
$query2="DELETE FROM products WHERE serialid = '".$ids."'";
mysqli_query($conn,$query2) or die("Invalid query");
}
}
$query2="SELECT * FROM products";
$allresult = mysqli_query($conn,$query2);
?>
<form method="POST" action="index.php">
<input type="submit" class="btn btn-danger" name="Delete" value="Delete"/>
<table class="table table-striped table-hover table-responsive" id="inventoryTable">
<thead>
<tr>
<td>Serial ID</td>
<td>Name</td>
<td>Manufacturer</td>
<td>Keys</td>
<td>Description</td>
<td>Category</td>
<td>Block</td>
<td>Floor</td>
<td>Room</td>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_array($allresult)) { ?>
<tr>
<td><input name="checkbox[]" type="checkbox" value="<?php echo $row['serialid']; ?>"></td>
<td><?php echo $row['serialid']?></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['manufacturer'] ?></td>
<td><?php echo $row['licensekeys'] ?></td>
<td><?php echo $row['description'] ?></td>
<td><?php echo $row['categoryname'] ?></td>
<td><?php echo $row['block'] ?></td>
<td><?php echo $row['floor'] ?></td>
<td><?php echo $row['room'] ?></td>
</tr>
<?php }?>
</tbody>
</table>
</form>
Good day. Im trying to have some functionality on my project, but im stuck with this.
I want to display my database depending on what the user select
Here is my html code:
<table>
<tr><td>Select Request Status:</td>
<td><select class="form-control" name="status" style="width:200px;">
<option value="1">Pending Request</option>
<option value ="2">Requests On-Process</option>
<option value="3">Unassigned Requests</option>
<option>All Requests</option>
</select></td>
</tr>
</table>
And here is my php code:
if ($status = $_SESSION['status'] == 'Pending Request')
{
$query = "select * from tblrequest where status='Pending Request'";
$request = mysql_query($query)or die(mysql_error());?>
<table class="table">
<tr>
<th>Request ID</th>
<th>Requestor</th>
<th>Department</th>
<th>Category</th>
<th>Assigned to</th>
<th>Status</th>
<th>Created Date</th>
<th>Created Time</th>
</tr>
<?php while($row = mysql_fetch_array($request)){
?>
<tbody class="table table-hover">
<tr>
<td style="width:100px;"><?php echo $row['RequestNumber']; ?></td>
<td style="width:100px;"><?php echo $row['Requestor']; ?></td>
<td style="width:100px;"><?php echo $row['Department']; ?></td>
<td style="width:50px;"><?php echo $row['category']; ?></td>
<td style="width:100px;"><?php echo $row['AssignedTo']; ?></td>
<td style="width:100px;"><?php echo $row['status']; ?></td>
<td style="width:100px;"><?php echo $row['DateRequested']; ?></td>
<td style="width:100px;"><?php echo $row['TimeRequested']; ?></td>
</tr>
</tbody>
<?php
}
}?>
Im a newbie to php so please help me.
Can you try this,
HTML:
<form method="post">
<table>
<tr><td>Select Request Status:</td>
<td>
<?php $Statuses = array("0"=>"All Requests", "1"=>"Pending Request", "2"=>"Requests On-Process", "3"=>"Unassigned Requests" );?>
<select class="form-control" name="status" style="width:200px;" onchange="this.form.submit();">
<?php foreach($Statuses as $key=>$status):?>
<?php
$selected ="";
$statusPost = $_POST['status'];
if($key == $statusPost): $selected =" selected"; endif;
?>
<option value="<?php echo $key;?>" <?php echo $selected;?>><?php echo $status;?></option>
<?php endforeach;?>
</select></td>
</tr>
</table>
</form>
PHP:
if (isset($_POST['status'])){
$status= $_POST['status'];
$Where ='';
if($status!='0'){
$Where =" where status='".$Statuses[$status]."' ;
}
}
$query = "select * from tblrequest $Where";
$request = mysql_query($query)or die(mysql_error());?>
<table class="table">
<tr>
<th>Request ID</th>
<th>Requestor</th>
<th>Department</th>
<th>Category</th>
<th>Assigned to</th>
<th>Status</th>
<th>Created Date</th>
<th>Created Time</th>
</tr>
<?php while($row = mysql_fetch_array($request)){
?>
<tbody class="table table-hover">
<tr>
<td style="width:100px;"><?php echo $row['RequestNumber']; ?></td>
<td style="width:100px;"><?php echo $row['Requestor']; ?></td>
<td style="width:100px;"><?php echo $row['Department']; ?></td>
<td style="width:50px;"><?php echo $row['category']; ?></td>
<td style="width:100px;"><?php echo $row['AssignedTo']; ?></td>
<td style="width:100px;"><?php echo $row['status']; ?></td>
<td style="width:100px;"><?php echo $row['DateRequested']; ?></td>
<td style="width:100px;"><?php echo $row['TimeRequested']; ?></td>
</tr>
</tbody>
<?php
}
?>
put select dropdown in a form with id,action,method etc.
give id to a select element(say "mySelect")
Now, in jquery,
$("#mySelect").on("change",function(){
if($("#mySelect").val() != ""))
{
$("#form1").submit();
}
})