2017-08-12 50 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>';