在 php 中制作一个扁平表

表有问题,为什么字段的行在所有寄存器中重复?


这是代码;


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


?>


翻阅古今
浏览 83回答 1
1回答

慕沐林林

您需要将字段行放在循环的一侧<?php// DB Query$result=mysqli_query($dbcon,$consult); $i=0;// Starting the tableprint ("<table>&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; <th>NIF</th>&nbsp; &nbsp; &nbsp; &nbsp; <th>Name</th>&nbsp; &nbsp; &nbsp; &nbsp; <th>lastname</th>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <th>Edad</th>&nbsp; &nbsp; </tr>");&nbsp; &nbsp; // Result loop&nbsp; &nbsp; while($row=mysqli_fetch_row($result)){&nbsp; &nbsp; &nbsp; &nbsp; // Table content&nbsp; &nbsp; &nbsp; &nbsp; print ("&nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row[0]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row[1]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row[2]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>".$row[3]."</td>&nbsp; &nbsp; &nbsp; &nbsp; </tr>");&nbsp; &nbsp; $i++;&nbsp; &nbsp; }&nbsp; &nbsp; // No results&nbsp; &nbsp; if ($i==0){&nbsp; &nbsp; &nbsp; &nbsp; print ("&nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td colspan='4'>No results</td>&nbsp; &nbsp; &nbsp; &nbsp; </tr>");&nbsp; &nbsp; }// Closing tableprint ("</table>");?>
打开App,查看更多内容
随时随地看视频慕课网APP