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
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
When I go to this page It's already search the blank string in the variable before pick the value in option. I just want to search the value when the button is click not automatically search when the user go to this page. And Also there's a problem on my "asc" in query.
If I go to this page. It's already search and show up the blank values
Already Search the Blank
And I insert this code $asc but as you can see in the picture it shows up an error but If I pick in the select option the error will vanish and show the value.
this Ascending to Descending
Please Enter Details Below
<div class="nice" style=" width:20%; margin-left:10%; z-index:100px;">
<div class="control-group">
<label class="control-label" for="inputPassword">Search Catalog:</label>
<div class="controls">
<select name="catalogs">
<option></option>
<?php $result = mysqli_query($dbcon,"select * from book_catalog")or die(mysqli_error());
while ($row=mysqli_fetch_array($result)){ ?>
<option value="<?php echo $row['catalog']; ?>"><?php echo $row['catalog']; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Author:</label>
<div class="controls">
<select name="status">
<option></option>
<option>Local</option>
<option>Foreign</option>
</select>
</div>
</div>
<div class="control-group" style="margin-left:210%; margin-top:-150px;">
<label class="control-label" for="inputPassword">Ascending-Descending</label>
<div class="controls">
<select name="asc" >
<option></option>
<option value="acc_id">Accession Number</option>
<option value="author">Author</option>
<option value="book_title">Book Title</option>
<option value="publisher_name">Publisher Name</option>
<option value="copyright_year">Copyright Year</option>
<option value="date_added">Date Added</option>
</select>
</div>
</div>
</div>
<input type="submit" name="submit" value="Search" style="margin-left:43%; margin-top:10%;" /> <br>
</form>
</div>
<?php
$selected_stat = "";
$selected_val = "";
$asc =""; // Storing Selected Value In Variable
if(isset($_POST['submit'])){
$selected_val = $_POST['status'];
$selected_stat = $_POST['catalogs'];
$asc = $_POST['asc']; // Storing Selected Value In Variable
}
?>
<br>
<thead>
<tr>
<th>Acc No.</th>
<th>Call Number</th>
<th>Author</th>
<th>Author Category</th>
<th>Book Title</th>
<th>Category</th>
<th>Book Copies</th>
<th>Publisher Name</th>
<th>Copyright Year</th>
<th>Date Added</th>
<th class="action">Action</th>
</tr>
</thead>
<tbody>
<?php $user_query=mysqli_query($dbcon,"select * from book where catalog = '$selected_stat' OR status = '$selected_val' ORDER BY book.$asc ASC")or die(mysqli_error($dbcon));
while($row=mysqli_fetch_array($user_query)){
$id=$row['book_id'];
?>
<tr class="del<?php echo $id ?>">
<td><?php echo $row['acc_id']; ?></td>
<td><?php echo $row['callnum']; ?></td>
<td><?php echo $row['author']; ?> </td>
<td><?php echo $row['status']; ?></td>
<td><?php echo $row['book_title']; ?> </div></td>
<td><?php echo $row ['catalog']; ?> </td>
<td class="action"><?php echo $row['book_copies']; ?> </td>
<td><?php echo $row['publisher_name']; ?></td>
<td><?php echo $row['copyright_year']; ?></td>
<td><?php echo $row['date_added']; ?></td>
<?php include('toolttip_edit_delete.php'); ?>
<td class="action">
<a rel="tooltip" title="Delete" id="<?php echo $id; ?>" href="#delete_book<?php echo $id; ?>" data-toggle="modal" class="btn btn-danger"><i class="icon-trash icon-large"></i></a>
<?php include('delete_book_modal.php'); ?>
<a rel="tooltip" title="Edit" id="e<?php echo $id; ?>" href="edit_book.php<?php echo '?id='.$id; ?>" class="btn btn-success"><i class="icon-pencil icon-large"></i></a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
Sorry for my bad english
When the SQL statement throws an error the best thing to do is log it or dump it to the screen so you can see it as actual SQL. Given the form of the statement I would think that $asc isn't what you think it is, it could possibly even be blank giving:
ORDER BY book. ASC
The book. being something the database can't deal with.
I think the issue with the page running a query automatically on load is because you are calling the query directly in your select element
<select name="catalogs">
<option></option>
<?php $result = mysqli_query($dbcon,"select * from book_catalog")or die(mysqli_error());
while ($row=mysqli_fetch_array($result)){ ?>
<option value="<?php echo $row['catalog']; ?>"><?php echo $row['catalog']; ?></option>
<?php } ?>
</select>
That PHP code isn't waiting for user input, it's just running immediately.
Make your query like this
mysqli_query($dbcon,"select * from book where catalog = '" . $selected_stat ."' OR status = '" . $selected_val ."' ORDER BY book." . $asc . " ASC")or die(mysqli_error($dbcon));
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>
I want to show a hidden div when I mouse over a link on my table cell. The event only fires up on the first row. This is what i did:
$(document).ready(function(){
$("#show_div").mouseover(function() {
$("#hello").css('visibility', 'visible');
});
$("#hello").mouseover(function() {
$("#hello").css('visibility', 'visible');
});
$("#hello").mouseout(function() {
$("#hello").css('visibility', 'hidden');
});
});
<form action="" method="post">
<table class="table table-bordered table-hover">
<div id="bulkOptionContainer" class="col-xs-4">
<select class="form-control" name="bulk_options" id="">
<option value="">Select Option</option>
<option value="publish">Publish</option>
<option value="draft">Draft</option>
<option value="delete">Delete</option>
</select>
</div>
<div class="col-xs-4">
<input class="btn btn-success" type="submit" name="submit" value="Apply"/>
<a class="btn btn-primary" href="posts.php?source=add_post">Add New</a>
</div>
<thead>
<tr>
<th><input type="checkbox" name="checkbox[]" id="selectAllCheckBoxes"></th>
<th>Id</th>
<th>Author</th>
<th scope="col">Title</th>
<th>Category</th>
<th>Status</th>
<th>Image</th>
<th>Tags</th>
<th>Comments</th>
<th>Date</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php $query = "SELECT * FROM post ORDER BY post_id DESC";
$result_set = mysqli_query($link, $query);
confirm_query($result_set);
while ($row = mysqli_fetch_assoc($result_set)):?>
<tr>
<td><label><input type="checkbox" class="checkBoxes" name="checkBoxArray[]"
value="<?php echo $row['post_id']; ?>"></label></td>
<td><?php echo $row['post_id'] ?></td>
<td><?php echo $row['post_author'] ?></td>
<td width="100%">
<!-- link to over-->
<a id="show_div"
href="../post.php?p_id=<?php echo $row['post_id'] ?>"><?php echo $row['post_title'] ?></a>
<!-- div to become visible on hover-->
<div id="hello" style="visibility:hidden;">
<p>post</p>
</div>
</td>
<td><?php echo sel_cat_byId($row['post_category_id']) ?></td>
<td><?php echo $row['post_status'] ?></td>
<td><img width="100" class="img-responsive" src="../images/<?php echo $row['post_image'] ?>"></td>
<td><?php echo $row['post_tag'] ?></td>
<td><?php echo $row['post_comment_count']; ?></td>
<td><?php echo $row['post_date'] ?></td>
<td><a class="btn btn-danger" href="posts.php?delete=<?php echo $row['post_id']; ?> "
onclick="alert('Are You Sure?')">Delete</a></td>
</td>
<td><a class="btn btn-success" href="posts.php?source=edit_post&edit=<?php echo $row['post_id']; ?>">Edit</a>
</td>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</form>
****the event only fires up on the first row.
Thanks
First replace your id with class and then try this
$(".show_div").mouseover(function() {
$(this).next(".hello").css('visibility', 'visible');
});
$(".show_div").mouseout(function() {
$(this).next(".hello").css('visibility', 'hidden');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<a class="show_div"
href="#">abc</a>
<!-- div to become visible on hover-->
<div class="hello" style="visibility:hidden;">
<p>post</p>
</div>
Im trying to have a simple select box that filters the database. I have successfully filled the database with all vallues on pageload, however I cant seem to get over the final hurdle of applying the filter. Also, once I have clicked the filter button, is it possible for the select text to stay at the text rather than returning to the default text?
[NOTE: I have pretty URL's enabled hence the no .php at the end]
The code is as followed:
<?php
$query = "SELECT * FROM Events";
echo $Type;
if (isset($_POST['filter'])) {
$Type = $_POST['value'];
$query .= " WHERE Type = '{$Type}'";
}
$result = mysql_query($query);
?>
<form action='/events' method="post" name="form_filter" >
<select class="eventList">
<option value="EVENT1">EVENT1</option>
<option value="EVENT2">EVENT2</option>
<option value="EVENT3">EVENT3</option>
<option value="EVENT4">EVENT4</option>
<option value="EVENT5">EVENT5</option>
<option value="EVENT6">EVENT6</option>
<input type="submit" name="filter" value="Filter">
</select>
</form>
<table class="table table-striped table-hover table-curved">
<thead>
<tr>
<th><b>Date</b></th>
<th><b>Event Name</b></th>
<th><b>Type</b></th>
<th><b>Region</b></th>
</tr>
</thead>
<tbody>
<?php while ($row = mysql_fetch_array($result)) { ?>
<tr>
<td><?php echo $Date = $row['Date']; ?></td>
<td><?php echo $Name = $row['Name']; ?></td>
<td><?php echo $Type = $row['Type']; ?></td>
<td><?php echo $Region = $row['Region']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
Your <select> does not have a name:
<select class="eventList" name="event">
Use that name as index in the $_POST array:
$Type = $_POST['event'];
Update your code as follow
<?php
$query = "SELECT * FROM Events";
echo $Type;
if (isset($_POST)) {
$Type = $_POST['event'];
$query .= " WHERE Type = '{$Type}'";
}
$result = mysql_query($query);
?>
<form action='/events' method="post" name="form_filter" >
<select class="eventList" name="event">
<option value="EVENT1" <?php echo ($Type=="EVENT1")?'selected="selected"':'';?>>EVENT1</option>
<option value="EVENT2" <?php echo ($Type=="EVENT2")?'selected="selected"':'';?>>EVENT2</option>
<option value="EVENT3" <?php echo ($Type=="EVENT3")?'selected="selected"':'';?>>EVENT3</option>
<option value="EVENT4" <?php echo ($Type=="EVENT4")?'selected="selected"':'';?>>EVENT4</option>
<option value="EVENT5" <?php echo ($Type=="EVENT5")?'selected="selected"':'';?>>EVENT5</option>
<option value="EVENT6" <?php echo ($Type=="EVENT6")?'selected="selected"':'';?>>EVENT6</option>
<input type="submit" name="filter" value="Filter">
</select>
</form>
<table class="table table-striped table-hover table-curved">
<thead>
<tr>
<th><b>Date</b></th>
<th><b>Event Name</b></th>
<th><b>Type</b></th>
<th><b>Region</b></th>
</tr>
</thead>
<tbody>
<?php while ($row = mysql_fetch_array($result)) { ?>
<tr>
<td><?php echo $Date = $row['Date']; ?></td>
<td><?php echo $Name = $row['Name']; ?></td>
<td><?php echo $Type = $row['Type']; ?></td>
<td><?php echo $Region = $row['Region']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
i have update this line
`if (isset($_POST)) {
and added the select name and code list code
$Type =$_POST['event'];
<select class="eventList" name="event">
<option value="EVENT1" <?php echo ($Type=="EVENT1")?'selected="selected"':'';?>>EVENT1</option>