如何从mysql表中获取行并将其填充到html表中
我是PHP和mysql新手,如果这是新手犯的错误,我很抱歉 我很难从mysql获取数据并将其填充到html表中 因此,我的脚本如下:如何从mysql表中获取行并将其填充到html表中,html,html-table,Html,Html Table,我是PHP和mysql新手,如果这是新手犯的错误,我很抱歉 我很难从mysql获取数据并将其填充到html表中 因此,我的脚本如下: <html> <head> </head> <body> <div class="well"> <table class="table table-striped"> <?php $userDetail = mys
<html>
<head>
</head>
<body>
<div class="well">
<table class="table table-striped">
<?php
$userDetail = mysql_query("SELECT * FROM uyePopup ORDER BY id LIMIT 100") or die(mysql_error());
$useridTable = "";
$userGenderTable = "";
$userMailTable = "";
while ($userRow = mysql_fetch_array($userDetail)) {
$useridTable.= '<td>' . $userRow['id'] . '</td>';
if ($userRow['gender'] == 1) {
$userRow['gender'] = 'M';
} else {
$userRow['gender'] = 'F';
}
$userGenderTable.= '<td>' . $userRow['gender'] . '</td>';
$userMailTable.= '<td>' . $userRow['email'] . '</td>';
}
// echo $userTable;
?>
<thead>
<tr>
<th>ID</th>
<th>Gender</th>
<th>E-mail</th>
</tr>
</thead>
<tbody>
<tr>
<?= $useridTable ?>
</tr>
<tr>
<?= $userGenderTable ?>
</tr>
<tr>
<?= $userMailTable ?>
</tr>
</tbody>
</table>
</div>
</body>
</html>
身份证件
性别
电子邮件
所以我有这样一个输出:
我在谷歌上搜索了很长时间,但似乎没有任何效果。这是未经测试的,但类似的东西应该可以:
<html>
<head>
</head>
<body>
<div class="well">
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Gender</th>
<th>E-mail</th>
</tr>
</thead>
<tbody>
<?php
$userDetail = mysql_query("SELECT * FROM uyePopup ORDER BY id LIMIT 100") or die(mysql_error());
while ($userRow = mysql_fetch_array($userDetail)) {
echo '<tr><td>' . $userRow['id'] . '</td>';
echo '<td>'.($userRow['gender'] == 1 ? 'M' : 'F').'</td>';
echo '<td>' . $userRow['email'] . "</td></tr>\n";
}
?>
</tbody>
</table>
</div>
</body>
</html>
身份证件
性别
电子邮件