2017-06-28 16 views
0

をフィールド。2入力を検索すると、これは検索フィールドがである私のインデックスページでPHPのMySQL

の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>"; 

       ?> 

私は別の検索フィールドを追加して、1つの検索ボタンで日付と場所の両方を検索し、両方の場所の広告日が満たされた結果を取得したいと考えています。

+0

単に別の入力テキストフィールドを追加し、それを使用しsubmit1するポストの名前を変更しますポスト変数。 – RJParikh

答えて

1

は別の入力

<input type="text" name="Location"> 
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) 
+1

私はこれを一度行いました、そして、結果を適切に得られませんでした。あなたの答えの後、私はもう一度試して、index.phpの検索名にエラーがあるのを見ました。私はseach.phpで言及したように "submit1"の代わりに "submit1"を入れてから働きました。どうもありがとう。 – Lisa234

1

ただ、場所の入力タイプを追加し、そのポスト変数で使用を追加します。

フォーム送信ボタンをクリックすると、サーバー側ですべての入力データが投稿されます。

また$_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()); 
+0

ありがとうございます。私の検索名があるインデックスページにもエラーがあります。 – Lisa234

+0

はい私はそれを変更し、search.phpに 'submit1'を与えました – RJParikh

関連する問題