2017-06-28 4 views
0

dies meine Index-Seite ist, wo die Suchfelder sind in.2 Eingabe der Suche Felder 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> 

das ist mein search.php Seite

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

       ?> 

I Ich möchte ein weiteres Suchfeld hinzufügen, in dem ich sowohl Datum als auch Ort in einer Suchschaltfläche suchen kann, um das Ergebnis zu erhalten, wenn das Anzeigendatum beider Standorte erfüllt ist.

+0

einfach eine andere Eingabetextfeld hinzufügen, und verwenden Sie es mit Variable posten. – RJParikh

Antwort

1

einen anderen Eingang hinzufügen

<input type="text" name="Location"> 

in php

$Location=$_POST['Location']; 

und in Abfrage

$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

Ich habe das einmal gemacht und ich habe das Ergebnis nicht richtig bekommen. Nach Ihrer Antwort habe ich es erneut versucht und festgestellt, dass mein Suchname in index.php fehlerhaft ist. Ich habe "submit1" anstelle von "submit" gesetzt, wie ich in seach.php erwähnt habe und dann hat es funktioniert. Danke vielmals. – Lisa234

1

Nur Eingangstyp für Standort hinzufügen und es mit seiner Post-Variable verwenden.

Wenn Sie auf die Schaltfläche "Senden" klicken, erhalten Sie alle Eingabedaten im Beitrag auf der Serverseite.

Ändern Sie auch den Namen des 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()); 
+0

danke. Außerdem gibt es einen Fehler in meiner Indexseite, wo ich meinen Suchnamen habe. – Lisa234

+0

Ja, ich habe es geändert und in der search.php 'submit1' gegeben – RJParikh