Php 在表中发布搜索结果需要帮助
我想在表格中显示搜索结果,有人能告诉我如何实现这样的目标吗?我从一个教程网站上获得了这段代码,但遗憾的是,它没有告诉我如何在一个四列表中获得结果。比如这个布局Php 在表中发布搜索结果需要帮助,php,sql,search,Php,Sql,Search,我想在表格中显示搜索结果,有人能告诉我如何实现这样的目标吗?我从一个教程网站上获得了这段代码,但遗憾的是,它没有告诉我如何在一个四列表中获得结果。比如这个布局 |图片|名称|描述|价格| <?php $conn = mysqli_connect("localhost", "root", "", "catalog"); if(mysqli_connect_errno()){ echo "Failed to connect: " . mysqli_connect_error();
|图片|名称|描述|价格|
<?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);
?>
要使用HTML将值显示到表中,只需修改$output变量即可
$output .= '<tr>
<td>' . $picture. '</td>
<td>' . $name . '</td>
<td>'. $description .'</td>
<td>'. $price .'</td>
</tr>';
$output.='
' . $照片。”
' . $名字。”
“.$description。”
“.$price。”
';
您需要在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>';
else{
$output=
“.$picture。”
“.$name。”
“.$description。”
“.$price。”
';
而($row=mysqli_fetch_数组($q)){…}
$output.='';
向我们展示您的尝试。很明显,您并没有真正尝试过将其放入表格中。这是问题的一部分,我对编码一无所知,不知道从哪里开始……从谷歌开始,用您在那里看到的内容修改代码。