Reputation: 163
I have a php web app that filters data between date range, but when i select date from two date time picker, it doesn't display, below is script and please tell me what am i missing?
By the way '$post_at" and '$post_at_to_date' are my variables to 2 date time picker:
$post_at = "FROM Date"
$post_at_to_date = "To Date"
<?php
if(isset($_POST['search']))
{
$post_at = $_POST['post_at'];
$post_at_to_date = $_POST['post_at_to_date'];
$cmbDept = $_POST["search"];
$query ="SELECT * FROM daily_data2 WHERE Checkdate BETWEEN '$post_at' and '$post_at_to_date' ";
$search_result = filter($query);
}
else {
$query = "SELECT * FROM daily_data2";
$search_result = filter($query);
}
function filter($query)
{
$connect = mysqli_connect("localhost", "root", "","bio_db");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
?>
And this is my action code:
<form name="frmSearch" method="post" action="index.php">
<p class="search_input">
<input type="text" placeholder="From Date" id="post_at" name="post_at" value="<?php echo $post_at; ?>" class="input-control" />
<input type="text" placeholder="To Date" id="post_at_to_date" name="post_at_to_date" style="margin-left:10px" value="<?php echo $post_at_to_date; ?>" class="input-control" />
<input type="submit" name="go" value="Search" >
</p>
For Fill table
<table align="center" width="600" border="1" cellpadding="1" cellspacing="1">
<tr>
<th>Userid</th>
<th>Name</th>
<th>Campaign</th>
<th>Checkdate</th>
<th>Hoursworked</th>
<th>Overtime</th>
</tr>
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td style="text-align:center;"><?php echo $row['Userid'];?></td>
<td width="200"><?php echo $row['Name'];?></td>
<td style="text-align:center;"><?php echo $row['Campaign'];?></td>
<td width="100" style="text-align:center;"><?php echo $row['Checkdate'];?></td>
<td style="text-align:center;"><?php echo $row['Hoursworked'];?></td>
<td style="text-align:center;"><?php echo $row['Overtime'];?></td>
</tr>
<?php endwhile;?>
</table>
SCRIPT for mysql which display and filter my data.
SELECT * FROM `daily_data2` WHERE Checkdate BETWEEN '2016-03-01' and '2016-03-31'
Upvotes: 0
Views: 870
Reputation: 2243
Missing
$post_at = $_POST["search"]['post_at'];
$post_at_to_date = $_POST["search"]['post_at_to_date'];
Full version
<?php
$post_at = "";
$post_at_to_date = "";
if(isset($_POST['search'])
&& isset($_POST['search']['post_at'])
&& isset($_POST['search']['post_at_to_date'])
) {
$post_at = $_POST["search"]['post_at'];
$post_at_to_date = $_POST["search"]['post_at_to_date'];
$query ="SELECT * FROM daily_data2 WHERE Checkdate BETWEEN '".$post_at."' and '".$post_at_to_date."' ";
$search_result = filter($query);
}
else {
$query = "SELECT * FROM daily_data2";
$search_result = filter($query);
}
function filter($query)
{
$connect = mysqli_connect("localhost", "root", "","bio_db");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
Upvotes: 1