首页 / PHP / php – 如何以表格格式显示数据
php – 如何以表格格式显示数据
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 如何以表格格式显示数据,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2078字,纯文字阅读大概需要3分钟。
内容图文
![php – 如何以表格格式显示数据](/upload/InfoBanner/zyjiaocheng/704/bfb25796241949f58e89e0b1b1debaca.jpg)
我想从mysql中搜索数据,需要在表格中显示它.在这里搜索数据是成功的,但数据没有显示在表格中,而是以直线显示.这里使用的是$output方法.我的编纂是
form.php的
<html dir="ltr" lang="en-US" >
<head>
<meta charset="UTF-8" />
<title>Search</title>
</head>
<body>
<h1>Seacrh By Name</h1>
<form action="search.php" method="get">
<label>Name:
<input type="text" name="keyname" />
</label>
<input type="submit" value="Search" />
</form>
</body>
</html>
search.php中
<?php
//capture search term and remove spaces at its both ends if the is any
$searchTerm = trim($_GET['keyname']);
//check whether the name parsed is empty
if($searchTerm == "")
{
echo "Enter name you are searching for.";
exit();
}
//database connection info
$host = "xx"; //server
$db = "xx"; //database name
$user = "xx"; //dabases user name
$pwd = "xx"; //password
//connecting to server and creating link to database
$link = mysqli_connect($host, $user, $pwd, $db);
//MYSQL search statement
$query = "SELECT * FROM customer_details WHERE id LIKE '%$searchTerm%'";
$results = mysqli_query($link, $query);
/* check whethere there were matching records in the table
by counting the number of results returned */
if(mysqli_num_rows($results) >= 1)
{
$output = "";
while($row = mysqli_fetch_array($results))
{
$output .= "id: " . $row['id'] . " ";
$output .= "name: " . $row['name'] . " ";
$output .= "Telephone: " . $row['Telephone'] . " ";
$output .= "E_mail: " . $row['E_mail'] . " ";
$output .= "visa_category: " . $row['visa_category'] . " ";
$output .= "other_category: " . $row['other_category'] . " ";
$output .= "passport_no: " . $row['passport_no'] . " ";
$output .= "remarks: " . $row['remarks'] . " ";
}
echo $output;
}
else
echo "There was no matching record for the name " . $searchTerm;
?>
如何在html表中显示我的数据.
解决方法:
您的$output仅输出数据本身.使它也输出HTML table.
echo '<table>
<tr>
<th>ID</th>
<th>Name</th>
</tr>';
while ($row = mysqli_fetch_array($results)) {
echo '
<tr>
<td>'.$row['id'].'</td>
<td>'.$row['name'].'</td>
</tr>';
}
echo '
</table>';
顺便说一下,不要直接向下滚动到代码,看看有关何时/如何使用表的警告.
内容总结
以上是互联网集市为您收集整理的php – 如何以表格格式显示数据全部内容,希望文章能够帮你解决php – 如何以表格格式显示数据所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。