这是搜索字段所在的索引页。
index.php
<form method="post" action="search.php?go" id="searchform">
<input type="text" name="Date">
<input type="submit" name="submit1" value="Search">
</form> 这是我的search.php页面
<?php
/* showing table after searching for date */
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
$Date=$_POST['Date'];
$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 . "%' 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>";
?>我想添加另一个搜索字段,我可以在一个搜索按钮中搜索日期和位置,并得到两个位置广告日期都满意的结果。
发布于 2017-06-28 09:11:04
添加另一个输入
<input type="text" name="Location"> in php
$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)发布于 2017-06-28 09:17:18
只需为location添加输入类型,并将其与post变量一起使用。
当您单击表单提交按钮时,它将在服务器端为您提供post中的所有输入数据。
还将post的名称更改为submit1 $_POST['submit1']
index.php
<form method="post" action="search.php?go" id="searchform">
<input type="text" name="Date">
<input type="text" name="Location">
<input type="submit" name="submit1" value="Search">
</form> search.php
<?php
/* showing table after searching for date */
if(isset($_POST['submit1'])){
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 Location = '".$Location."' Date LIKE '%" . $Date . "%' ORDER BY location DESC, LabourSupplier ASC",$connection)
or die("Failed to query database" .mysql_error());https://stackoverflow.com/questions/44798219
复制相似问题