如何在单击搜索按钮并在同一页面上打印结果后同时保留搜索查询框和字母搜索


How to retain both the search query box and the alphabetical search after clicking on search button and printing result on the same page

我已经创建了我的PHP页面,我已经搜索了查询字段和按字母顺序搜索。提交查询后,我在同一页上打印结果。查询工作得很好,但我希望结果显示在相同的地方,我从字母搜索得到结果。即按字母顺序搜索是消失后,结果来自搜索框。如何在网页中同时保留它们?

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
  <input type="text" name="query" />
  <input type="submit" value="Search" />
</form>
<?php
  session_start();  
  $con=mysqli_connect("localhost","root","","journalskart"); /*Database    Connection*/
      //include('inc/search.php');
      $errormsg= "No Record Found...!";
      //search box script start from here
      $alpha = $_GET['query'];
      $min_length = 3;
      if(strlen($alpha) >= $min_length){ // if query length is more or equal minimum length then
          $alpha = htmlspecialchars($alpha); 
          // changes characters used in html to their equivalents, for example: < to &gt;
          $alpha = mysqli_real_escape_string($con, $alpha);
          // makes sure nobody uses SQL injection
          $q1 = mysqli_query($con,"SELECT * FROM vendor1
          WHERE (title LIKE '%".$alpha."%') OR (publisher LIKE '%".$alpha."%')") or die(mysqli_error($con));    
          //$noofresult = mysqli_num_rows($q1);
         //echo "$noofresult Result Found<br/>";
         $num_rows=mysqli_num_rows($q1);
         if($num_rows > 0)
         { // if one or more rows are returned do following
              while($roww = mysqli_fetch_array($q1)){

               $_SESSION["Title"] = $roww['title']; 
               $_SESSION["Fullset"] = $roww["full_set"];
             $_SESSION["ISSN"] = $roww["issn"]; 
             $_SESSION["Publisher"] = $roww["publisher"]; 
             $_SESSION["Freq"] = $roww["freq"]; 
             $_SESSION["Volume"] = $roww["volume"]; 
             $_SESSION["Issue"] = $roww["issue"]; 
             $_SESSION["Year"] = $roww["year"]; 
                 $_SESSION["Price"] = $roww["price"]; 
             }
             }
             else{ // if there is no matching rows do following
              echo "No results";
            }   
            }//search box script end here
          else{ 


        $alpha="%";
        if (isset($_REQUEST['alpha'])) {
        $alpha = $_REQUEST['alpha']."%";
        }
        $q1 = mysqli_query($con, "select * from vendor1 where title like '$alpha%' " );
      ?>
<div >
  <form action="" method="post" >
    <table  >
      <tr>
        <td>
          <div  style="float:left;">
            <CENTER>
              <FONT COLOR=Green>Sort by Alphabet:</FONT>  
              <A HREF="<?php echo $_SERVER['PHP_SELF']; ?>" >All</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=A">A</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=B">B</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=C">C</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=D">D</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=E">E</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=F">F</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=G">G</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=H">H</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=I">I</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=J">J</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=K">K</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=L">L</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=M">M</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=N">N</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=O">O</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=P">P</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=Q">Q</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=R">R</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=S">S</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=T">T</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=U">U</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=V">V</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=W">W</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=X">X</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=Y">Y</A>
              <FONT COLOR=Green>|</FONT> <A HREF="?alpha=Z">Z</A>
            </CENTER>
          </div>
        </td>
      </tr>
      <tr>
        <th>Title</th>
        <th>Full Set</th>
        <th>ISSN</th>
        <th>Publisher</th>
        <th>Freq</th>
        <th>Volume</th>
        <th>Issue</th>
        <th>Year</th>
        <th>Price</th>
      </tr>
      <tbody>
        <?php
          $i=1;
          $num_rows=mysqli_num_rows($q1);
          if($num_rows==0)
          {
          ?>
        <div align="center">
          <div class="alert alert-danger alert-dismissable">
            <?php echo $errormsg; ?>
          </div>
        </div>
        <?php
          }
          else
          {
          while($roww=mysqli_fetch_array($q1))
          {   
          $_SESSION["Title"] = $roww['title']; 
                   $_SESSION["Fullset"] = $roww["full_set"];
                 $_SESSION["ISSN"] = $roww["issn"]; 
                 $_SESSION["Publisher"] = $roww["publisher"]; 
                 $_SESSION["Freq"] = $roww["freq"]; 
                 $_SESSION["Volume"] = $roww["volume"]; 
                 $_SESSION["Issue"] = $roww["issue"]; 
                 $_SESSION["Year"] = $roww["year"]; 
                     $_SESSION["Price"] = $roww["price"];
            ?>
        <tr>
          <td>
            <div style="height:100px;float:left;">
              <input name="" type="checkbox" value="">
            </div>
            <div >
              <a href="#">  <b><?php echo $_SESSION["Title"]; ?></b></a>
          <td><?php echo $_SESSION["Fullset"]; ?></td>
          <td><?php echo $_SESSION["ISSN"]; ?></td>
          <td><?php echo $_SESSION["Publisher"]; ?></td>
          <td><?php echo $_SESSION["Freq"]; ?></td>
          <td><?php echo $_SESSION["Volume"]; ?></td>
          <td><?php echo $_SESSION["Issue"]; ?></td>
          <td><?php echo $_SESSION["Year"]; ?></td>
          <td><?php echo $_SESSION["Price"]; ?></td>
          </div></td>
        </tr>
        <?php }
          $i++;
          }
          }
          echo "$num_rows Results Found";
          ?>
      </tbody>
    </table>
  </form>
</div>
</body></html>
<SCRIPT LANGUAGE=JavaScript>
  <!--
    document.write(ALPHABET())
    //-->
</SCRIPT>

尝试使用基于条件的检查来查看是否进行了搜索

<?php  
//general declarations
if ($_SERVER["REQUEST_METHOD"] == "GET") {  
    //body of your php code execution  
}  
?>php
<html>  
//your html body  
</html>