为了账号安全,请及时绑定邮箱和手机立即绑定

在 php 中制作一个扁平表

在 php 中制作一个扁平表

PHP
翻阅古今 2022-09-03 14:42:39
表有问题,为什么字段的行在所有寄存器中重复?这是代码;<?php------------------$result=mysqli_query($dbcon,$consult);while($row=mysqli_fetch_row($result)){echo "<table><tr><th>NIF</th><th>Name</th><th>lastname</th> <th>Edad</th></tr>";echo "<tr><td>";echo $row[0]."</td><td>";echo $row[1]."</td><td>";echo $row[2]."</td><td>";echo $row[3]."</td></tr>";}echo "</table>";?>
查看完整描述

1 回答

?
慕沐林林

TA贡献2016条经验 获得超9个赞

您需要将字段行放在循环的一侧


<?php


// DB Query

$result=mysqli_query($dbcon,$consult); $i=0;


// Starting the table

print ("

<table>

    <tr>

        <th>NIF</th>

        <th>Name</th>

        <th>lastname</th> 

        <th>Edad</th>

    </tr>");


    // Result loop

    while($row=mysqli_fetch_row($result)){

        // Table content

        print ("

        <tr>

            <td>".$row[0]."</td>

            <td>".$row[1]."</td>

            <td>".$row[2]."</td>

            <td>".$row[3]."</td>

        </tr>");

    $i++;

    }


    // No results

    if ($i==0){

        print ("

        <tr>

            <td colspan='4'>No results</td>

        </tr>");

    }


// Closing table

print ("</table>");


?>


查看完整回答
反对 回复 2022-09-03
  • 1 回答
  • 0 关注
  • 74 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信