首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >搜索2个输入字段PHP MySQL

搜索2个输入字段PHP MySQL
EN

Stack Overflow用户
提问于 2017-06-28 09:08:31
回答 2查看 299关注 0票数 0

这是搜索字段所在的索引页。

index.php

代码语言:javascript
复制
      <form  method="post" action="search.php?go"  id="searchform"> 
        <input  type="text" name="Date"> 
        <input  type="submit" name="submit1" value="Search"> 
      </form> 

这是我的search.php页面

代码语言:javascript
复制
<?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>"; 

                ?>

我想添加另一个搜索字段,我可以在一个搜索按钮中搜索日期和位置,并得到两个位置广告日期都满意的结果。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-06-28 09:11:04

添加另一个输入

代码语言:javascript
复制
    <input  type="text" name="Location"> 

in php

代码语言:javascript
复制
$Location=$_POST['Location'];

以及在查询中

代码语言:javascript
复制
 $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)
票数 1
EN

Stack Overflow用户

发布于 2017-06-28 09:17:18

只需为location添加输入类型,并将其与post变量一起使用。

当您单击表单提交按钮时,它将在服务器端为您提供post中的所有输入数据。

还将post的名称更改为submit1 $_POST['submit1']

index.php

代码语言:javascript
复制
  <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

代码语言:javascript
复制
<?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());
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44798219

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档