我有一個php文件,它將從另一個php文件獲取輸入,並在html表中顯示數據,但是在sql語句中,我沒有獲取在其中過濾的日期字段,可能是日期格式是不正確的。請幫我這個在兩個日期之間選擇記錄
我的代碼如下
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("marketnews", $con);
$date1 = explode('/', $_POST['ADate']);
$time = mktime(0,0,0,$date1[0],$date1[1],$date1[2]);
$mysqldate = date('Y-m-d H:i:s', $time);
$date2 = explode('/', $_POST['BDate']);
$time = mktime(0,0,0,$date2[0],$date2[1],$date2[2]);
$mysqldate1 = date('Y-m-d H:i:s', $time);
$sec= "$_POST[id]";
echo "<br>";
echo "$mysqldate1";
echo "<br>";
echo "$sec";*/
$result = mysql_query("SELECT * FROM mktnews where security = '$sec' and eventdate between '$mysqldate' and '$mysqldate1'");
echo '<a href="main.html"><b>BACK</b></a>';
echo "<br>";
echo "<table border='2' BORDERCOLOR=GREEN align='center' >
<tr>
<th>Firm</th>
<th>Name</th>
<th>NIC</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['eventdate'] . "</td>";
echo "<td>" . $row['news'] . "</td>";
echo "<td>" . $row['security'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
這個MySQL表的日期格式是這樣
2013-04-11
請幫我這個
什麼是您的日期字段的數據類型..? – alwaysLearn
和一個建議..請避免使用mysql_ *函數他們折舊.. – alwaysLearn