2017-08-12 77 views
-1

我想在表格中顯示此搜索的結果,任何人都可以告訴我如何才能實現這樣的事情嗎?我從教程網站獲得了這段代碼,但是它並沒有告訴我如何在四列表中獲得我的結果。比如這個佈局。在需要幫助的表格中發佈搜索結果


|圖片|名稱|描述|價格|

<?php 

$conn = mysqli_connect("localhost", "root", "", "catalog"); 

if(mysqli_connect_errno()){ 
    echo "Failed to connect: " . mysqli_connect_error(); 
} 

error_reporting(0); 

$output = ''; 

if(isset($_GET['q']) && $_GET['q'] !== ' '){ 
    $searchq = $_GET['q']; 

    $q = mysqli_query($conn, "SELECT * FROM final_dog_catologue_full WHERE name LIKE '%$searchq%' OR brand LIKE '%$searchq%'") or die(mysqli_error()); 
    $c = mysqli_num_rows($q); 
    if($c == 0){ 
     $output = 'No search results for <b>"' . $searchq . '"</b>'; 
    } else { 
     while($row = mysqli_fetch_array($q)){ 
      $Name = $row['Name']; 
      $brand = $row['Brand']; 
      $picture = $row['Picture']; 
      $description = $row['description']; 
      $Retail_Price_With_Delievery = $row['Price']; 

      $output .= '<a href="' . $brand . '"> 
         <h3>' . $brand . '</h3> 
          <p>'. $brand .'</p> 
         </a>'; 
     } 
    } 
} else { 
    header("location: ./"); 
} 
print("$output"); 
mysqli_close($conn); 

?> 
+0

向我們展示您嘗試過的。很明顯,你並沒有真正嘗試過把它放到桌子上。 –

+0

這是問題的一部分,我是新來的編碼,並且對於從哪裏開始幾乎沒有想法... –

+0

從Google搜索開始[html table](https://www.tutorialspoint.com/html/html_tables.htm) ,並用你在那裏看到的代碼擺弄你的代碼。 –

回答

-1

要使用HTML顯示值到一個表,只需修改$輸出變量

$output .= '<tr> 
       <td>' . $picture. '</td> 
       <td>' . $name . '</td> 
       <td>'. $description .'</td> 
       <td>'. $price .'</td> 
      </tr>'; 

您將需要添加的「表」標籤之前和之後while循環

else { 
$output = '<table><tr> 
      <th>' . $picture. '</th> 
      <th>' . $name . '</th> 
      <th>'. $description .'</th> 
      <th>'. $price .'</th> 
      </tr>'; 
while($row = mysqli_fetch_array($q)){...} 
$output .= '</table>';