我有一个数据表,我正在尝试根据日期添加搜索功能,但我无法得到结果在这里是我的代码:
<form action="search.php" id="searchform" method="POST" class="searchbox-container">
<input type="text" id="searchbox" placeholder="Search" name="searchbox" class="searchbox" />
<input type="datetime-local" name="date">
<select name="select" id="select">
<option value="type">Type</option>
<option value="name">Name</option>
</select>
<input type="submit" name="search" class="searchbox-btn" value="Go" />
</form>
<?php
此处连接:
$date=$_POST['date'];
if($_POST['select']=="type"){
$sqlcommand="SELECT * FROM eventform WHERE event_type LIKE '%$search%'";
}
elseif($_POST['select']=="name"){
$sqlcommand="SELECT * FROM eventform WHERE event_name LIKE '%$search%'";
}
else {
if($date!=0)
$sqlcommand="SELECT * FROM eventform WHERE start_date LIKE '$date'";
}
$sqldata=mysqli_query($con,$sqlcommand)
or die("Error Getting Data");
$count=mysqli_num_rows($sqldata);
if($count!=0){
echo "<table border=2 bordercolor=#440000 cellpadding=2 bgcolor=#DDDDDD width=100%>";
echo "<tr bgcolor=#555555 style=font-size:18px align=center><th>Event Code</th><th>Event Name</th><th>Event Type</th><th>Event Level</th><th>Start Date</th>
<th>End Date</th><th>Point</th><th>Picture</th><th>Video</th><th>Description</th></tr>";
while($row=mysqli_fetch_array($sqldata)){
echo "<tr align=center><td>";
echo $row['event_code'];
echo "</td><td>";
echo $row['event_name'];
echo "</td><td>";
echo $row['event_type'];
echo "</td><td>";
echo $row['event_level'];
echo "</td><td>";
echo $row['start_date'];
echo "</td><td>";
echo $row['end_date'];
echo "</td><td>";
echo $row['points'];
echo "</td><td>";
echo $row['pic'];
echo "</td><td>";
echo $row['video'];
echo "</td><td>";
echo $row['description'];
echo "</td></tr>";
}
echo "</table>";
当我根据事件的类型和名称进行搜索时,我得到了结果,但是当我想根据日期和时间进行搜索时,它只是不起作用。
答案 0 :(得分:0)
您的日期字段的格式是时间戳? 对于时间戳,请执行:
$sqlcommand="SELECT * FROM eventform WHERE start_date > '".$date."' ORDER BY start_date DESC";
或日期yy-mm-dd
格式,只需:
$sqlcommand="SELECT * FROM eventform WHERE start_date = '".$date."' ORDER BY start_date DESC";