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.