搜索结果显示

时间:2018-08-11 19:32:04

标签: php mysqli php-mysqlidb

我有一个网站项目,客户需要搜索并显示结果,所以我已完成了所有工作,但是问题是出现搜索结果时,如果有多于1行,则会使结果重复在同一行上,这是代码。

 <h1 style="font-family:calibri;color:#13CC0D;text-align:center;">BODABODA SEARCH RESULTS</h1>
<table cellpadding="1" cellspacing="1" id="resultTable">
                        <thead>
                            <tr>
                                <th style="border-left: 1px solid #C1DAD7"> Region</th>
                                <th> District </th>
                                <th> Ward </th>
                                <th> Street</th>
                                <th> Driver Name </th>
                                <th>Identification Type</th>
                                <th>Identification Number</th>
                                <th>Motorcycle Type</th>
                                <th>Motorcycle Reg No</th>
                                <th>Phone Number</th>
                            </tr>
                        </thead>

<?php
  $conn = mysqli_connect('localhost', 'efalococ_calcia', '*ad4@zNQ=nfN') or die('can not connect to the server'.mysqli_error);
 mysqli_select_db($conn, 'efalococ_safirii');
  if(isset($_POST['search'])){
      $query  =  $_POST['region'];
      $query1 =  $_POST['district'];
      $query2 =  $_POST['ward'];
      $query3 =  $_POST['street'];

      $results = mysqli_query($conn,"SELECT * FROM bodaboda WHERE (`region` LIKE '%".$query."%') && (`district` LIKE '%".$query1."%') && (`ward` LIKE '%".$query2."%') && (`street` LIKE '%".$query3."%')") or die(mysql_error());
      if(mysqli_num_rows($results) >0){
          while($row = mysqli_fetch_array($results)){
         echo "<td>".$row['Region']."</td>" ;
         echo "<td>".$row['District']."</td>";
         echo "<td>".$row['Ward']."</td>";
         echo "<td>".$row['Street']."</td>";
         echo "<td>".$row['DriverName']."</td>";
         echo "<td>".$row['IdentificationType']."</td>";
         echo "<td>".$row['IdentificationNumber']."</td>";
         echo "<td>".$row['MotorcycleType']."</td>";
         echo "<td>".$row['MotorcycleRegNo']."</td>";
         echo "<td>".$row['PhoneNumber']."</td>";
          }
      }else{
          echo '<span style="color:red;font-family:cursive;font-size:14px;">No results found, Please Modify your search&nbsp;</span> <a href="search_bodaboda.php" style="font-family:cursive;text-decoration:none;font-size:14px;">Click here</a>'.mysqli_error($conn);
      }
  }
?>
 </table>

And the results shows like this!

您能帮忙吗?有什么主意吗?

1 个答案:

答案 0 :(得分:1)

您只需要为每行使用<tr>

  

标记在HTML表格中定义了一行。

详细了解HTML tr tag

 while($row = mysqli_fetch_array($results)) {
     echo "<tr>";
     echo "<td>".$row['Region']."</td>" ;
     echo "<td>".$row['District']."</td>";
     echo "<td>".$row['Ward']."</td>";
     echo "<td>".$row['Street']."</td>";
     echo "<td>".$row['DriverName']."</td>";
     echo "<td>".$row['IdentificationType']."</td>";
     echo "<td>".$row['IdentificationNumber']."</td>";
     echo "<td>".$row['MotorcycleType']."</td>";
     echo "<td>".$row['MotorcycleRegNo']."</td>";
     echo "<td>".$row['PhoneNumber']."</td>";
     echo "</tr>";
 }