我正在尝试以有序的方式显示我的所有表格行
database table = u_visits
rows = id/ip_adress/visits/dates
这是我的代码:
<html>
<body>
<?php
include 'includes/connect3.php';
$result = mysqli_query($con,"SELECT * FROM u_visits");
$num = mysqli_num_rows($result);
?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td>
<font face="Arial, Helvetica, sans-serif">Value1</font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif">Value2</font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif">Value3</font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif">Value4</font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif">Value5</font>
</td>
</tr>
<?php
$i=0;
while ($i < $num) {
$f1 = mysqli_result($result,$i,"id");
$f2 = mysqli_result($result,$i,"ip_adress");
$f3 = mysqli_result($result,$i,"visits");
$f4 = mysqli_result($result,$i,"dates");
?>
<tr>
<td>
<font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font>
</td>
</tr>
<?php$i++;}
?>
</body>
</html>
提前感谢您的帮助! 如果这不是我试图完成的方式,我会接受新的建议再次感谢。
答案 0 :(得分:0)
为什么获得数据后的排序?为什么不要求数据库返回已订购的数据。
SELECT * id, ip_adress, visits, dates FROM u_visits ORDER BY id ASC
这是ORDER BY之美,给它一个列索引和一个订购方向。