目前我正在开发一个网站正常运行时搜索引擎但是我有一个愚蠢的问题.我想在表中输出多个mysql行,但是下面的代码会导致为找到的每一行创建一个单独的表.提前感谢您的协助 $searchTerm = trim($_GET[searchterm...
目前我正在开发一个网站正常运行时搜索引擎但是我有一个愚蠢的问题.我想在表中输出多个mysql行,但是下面的代码会导致为找到的每一行创建一个单独的表.提前感谢您的协助
$searchTerm = trim($_GET['searchterm']);
//check whether the name parsed is empty
if($searchTerm == "")
{
echo "Please enter something to search for...";
exit();
}
//database connection info
$host = "localhost"; //server
$db = "DB NAME"; //database name
$user = "USER"; //dabases user name
$pwd = "PASSWORD"; //password
$link = mysqli_connect($host, $user, $pwd, $db);
$query = "SELECT * FROM sites WHERE name OR des LIKE '%$searchTerm%'";
$results = mysqli_query($link, $query);
if(mysqli_num_rows($results) >= 1)
{
while($row = mysqli_fetch_array($results))
{
echo '<table class="table table-striped table-bordered table-hover">';
echo"<TR><TD>Name</TD><TD>Description:</TD><TD>Status</TD></TR>";
echo "<tr><td>";
echo $row['name'];
echo "</td><td>";
echo $row['des'];
echo "</td><td>";
echo $row['status'];
echo "</TD></tr>";
echo "</table>";
}
}
else
echo "There was no matching record for the name " . $searchTerm;
?>
解决方法:
用if替换if中的while:
echo '<table class="table table-striped table-bordered table-hover">';
echo "<tr><th>Name</th><th>Description:</th><th>Status</th></tr>";
while($row = mysqli_fetch_array($results))
{
echo "<tr><td>";
echo $row['name'];
echo "</td><td>";
echo $row['des'];
echo "</td><td>";
echo $row['status'];
echo "</td></tr>";
}
echo "</table>";
沃梦达教程
本文标题为:php输出从mysql到html表
猜你喜欢
- php – 如何将HTML表单中的数字添加到数据库中已有的数字? 2023-10-26
- Vue实现电梯样式锚点导航效果流程详解 2023-07-10
- 微信小程序自动化部署的全过程 2022-08-31
- JS判断传入函数的参数是否为空(函数参数是否传递) 2023-08-08
- Ajax的简单实用实例代码 2023-02-01
- IE8/IE9下Ajax缓存问题 2023-01-20
- 关于 internet explorer:浏览器特定的 css 属性 2022-09-21
- JavaScript实现网页带动画返回顶部的方法详解 2022-10-22
- 前端面试复盘:vue技术面没有难倒我,hr面却是一把挂 2023-10-08
- 防止重复发送Ajax请求的解决方案 2022-12-15