I am trying to create a filter for a table using a "To" and "From" date range filter for a MySQL table. I cannot get the selected dates to query the information.
Only display data if the dates are selected. If the dates are null input fields, the table should display all rows and data.
Table:
| Username | Full Name | Manager | Review Date | Total Score |
|-------------------------------------------------------------|
| sjohn | John Smith| John Dow | 2015-01-31 | 80% |
| sjane | Jane Smith| John Dow | 2015-02-01 | 80% |
| jmike | Mike Dow | Jane Dow | 2015-02-02 | 75% |
| dmia | Mia Dow | Rob Smith| 2015-02-10 | 90% |
If I create a form with input fields, I would like to query the table by "fromDate" and "toDate" dates using the Review Date Column.
Problem: For some reason, the variables are not storing, or passing through the SQL statement.
<form action="eerevuiew.php" method="POST">
<label for="from">From</label>
<input type="text" id="datepicker" name="fromDate"/>
<label for="to">to</label>
<input type="text" id="datepicker2" name="toDate"/>
<input name="" type="submit" />
</form>
<?php
$min = intval($_POST['fromDate']);
$max = intval($_POST['toDate']);
?>
<?php
$con = mysqli_connect('localhost','root','123456','employeescore');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"employeescore");
$sql="SELECT * FROM vwscore WHERE reviewdate BETWEEN '".$min."' AND '".$max."'";
$result = mysqli_query($con,$sql);
?>
<?php
echo "<table border='1'>
<tr>
<th>Username</th>
<th>Full Name</th>
<th>Manager</th>
<th>Review Date</th>
<th>Total Score</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['display_name'] . "</td>";
echo "<td>" . $row['manager'] . "</td>";
echo "<td>" . $row['reviewdate'] . "</td>";
echo "<td>" . $row['total_score'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
I am using a jQuery Function for the datepicker.
Thanks for all your help!