gpt4 book ai didi

php - 尝试使用 PHP 和 html 显示来自 mysql 的数据

转载 作者:行者123 更新时间:2023-11-29 07:06:31 25 4
gpt4 key购买 nike

我正在尝试使用 PHP 将来自 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

我该怎么办?请帮忙。

最佳答案

<?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>

关于php - 尝试使用 PHP 和 html 显示来自 mysql 的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7010684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com