我想在輸入日期並單擊搜索按鈕時在兩個日期之間得到結果。目前爲止,我只能進行一次日期搜索。這是它如何顯示。 在手動輸入的兩個日期之間搜索
這是我的index.php
<form method="post" action="search.php?go" id="searchform">
<input type="text" name="Date" placeholder="Date">
<input type="text" name="Location" placeholder="Location">
<input type="submit" name="submit" value="Search">
</form>
這就是我得到的搜索結果。 的search.php
<?php
/* showing table after searching for date */
if (isset($_POST['submit'])) {
if (isset($_GET['go'])) {
$Date = $_POST['Date'];
$Location = $_POST['Location'];
$query = mysql_query("SELECT ID,Name,Location,Date,Category,LabourSupplier,InTime,OutTime,Day,DayRate,Salary,OTHours,OTrate,OTAmount,Allowance2,TotalSalary,Advance,SalaryToHand FROM attendance WHERE Date LIKE '%" . $Date . "%' AND Location LIKE '%" . $Location . "%' ORDER BY location DESC, LabourSupplier ASC", $connection)
or die("Failed to query database" . mysql_error());
while ($row = mysql_fetch_array($query)) {
print "<tr>";
print "<td >" . $row['ID'] . "</td>";
print "<td >" . $row['Name'] . "</td>";
print "<td >" . $row['Location'] . "</td>";
print "<th >" . $row['Date'] . "</th>";
print "<td >" . $row['Category'] . "</td>";
print "<td >" . $row['LabourSupplier'] . "</td>";
print "<th >" . $row['InTime'] . "</th>";
print "<th >" . $row['OutTime'] . "</th>";
print "<th >" . $row['Day'] . "</th>";
print "<th >" . $row['DayRate'] . "</th>";
print "<th >" . $row['Salary'] . "</th>";
print "<th >" . $row['OTHours'] . "</th>";
print "<th >" . $row['OTrate'] . "</th>";
print "<th >" . $row['OTAmount'] . "</th>";
print "<th >" . $row['Allowance2'] . "</th>";
print "<th >" . $row['TotalSalary'] . "</th>";
print "<th >" . $row['Advance'] . "</th>";
print "<th>" . $row['SalaryToHand'] . "</th>";
print "</tr>";
}
}
}
print "</table>";
?>
不要使用mysql_ *功能annymore使用mysqli_ *功能或PDO。 mysql_ *函數已被棄用 –
您的SQL查詢很容易出現SQL注入 –
忘記所有這些PHP的東西;這與你的問題無關,而且非常非常過時。相反,請參閱:[爲什麼我應該爲我認爲是非常簡單的SQL查詢提供一個MCVE?](https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an- mcve-for-what-looks-to-what-seems-to-very-simple-sql-query) – Strawberry