php显示表格,php – 如何以表格格式显示数据

我想从mysql中搜索数据,需要在表格中显示它.在这里搜索数据是成功的,但数据没有显示在表格中,而是以直线显示.这里使用的是$output方法.我的编纂是

form.php的

Search

Seacrh By Name

Name:

search.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 '

IDName

while ($row = mysqli_fetch_array($results)) {

echo '

'.$row['id'].''.$row['name'].'';

}

echo '

';

顺便说一下,不要直接向下滚动到代码,看看有关何时/如何使用表的警告.

标签:html,php,mysql

来源: https://codeday.me/bug/20191002/1844721.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值