我正在尝试使用像这样的
来显示来自mysql数据库的数据作为表格格式 $query = "SELECT CONCAT(usrFirstname,'',usrSurname) As FullName,usrNickname AS Nickname,";
$query.= "usrEmail As EmailAddress,usrGender AS Gender,DATE(usrDOB) As DOB,usrBelt AS BeltId,ggName As Groupname ";
$query.= "FROM user LEFT JOIN gyg ON user.usrIndex = gyg.usrIndex;";
$result = mysql_query($query);
echo mysql_error();
if($result)
{
$row= mysql_fetch_array($result);
if($row)
{
$fullname = $row['FullName'];
$nickname = $row['Nickname'];
$emialid = $row['EmailAddress'];
$gender = $row['Gender'];
$Dateofbirth = $row['DOB'];
$belt = $row['BeltId'];
$group = $row['Groupname'];
}
}
和html代码是这样的:
<table height= "600" width="800">
<tr style="vertical-align: top; text-align:top display:inline-block">
<thead>
<td>FUll name</td><td> Nickname<?php echo $nickname ?></td><td>Email Address<?php echo $emialid ?></td><td>Gender<?php echo $gender ?></td><td>DOB <?php echo $Dateofbirth ?><td>BELT ID <?php echo $belt ?></td><td>GROUP <?php echo $group ?></td>
</thead>
</tr>
</table>
我想这样表现出来:
fullname nickname emailid gender dob beltid group
xxxxx xxxxx xxxxx xxx xxx xxx xxxx
xxxxx xxxxx xxxxx xxx xxx xxx xxxx
但显示如下:
fullname xxxxx nickname xxxxx emailid xxxxx gender xxxxx dobxxxxx beltid xxxxx groupxxxxx
我有四行来自数据库,但它只显示一行。
我该如何解决这个问题?任何人都可以帮忙吗?
修改后的代码:显示如下:
fullname nickname emailid gender dob beltid group
xxxxx xxxxx xxxxx xxx xxx xxx xxxx
xxxxx xxxxx xxxxx xxx xxx xxx xxxx
我该怎么办?请帮忙。
答案 0 :(得分:2)
<?php
$rows = array();
if($result)
{
while($row=mysql_fetch_assoc($result)){
$rows[] = $row;
}
}
<table height= "600" width="800">
<tr style="vertical-align: top; text-align:top display:inline-block">
<thead>
<tr>
<td>FUll name</td>
<td> Nickname</td>
<td>Email Address</td>
<td>Gender</td>
<td>DOB</td>
<td>BELT ID</td>
<td>GROUP</td>
</tr>
</thead>
<?php foreach ($rows as $row){?>
<tr>
<td><?php echo $row['fullname']?></td>
<td><?php echo $row['nickname']?></td>
<!--other fields here-->
<td><?php echo $row['GROUP']?></td>
</tr>
<?php }?>
</tr>