我想在表格中显示此搜索的结果,是否有人能够告诉我如何才能实现这样的事情呢?我从一个教程网站获得了这个代码,但是它并没有告诉我如何在四列表中获得我的结果。比如这种布局。
|图片名称|说明|价格|
<?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 :(得分:-1)
要使用HTML将值显示到表中,只需修改$ output变量
即可$output .= '<tr>
<td>' . $picture. '</td>
<td>' . $name . '</td>
<td>'. $description .'</td>
<td>'. $price .'</td>
</tr>';
您需要在while循环
之前和之后添加“table”标签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>';