0

我正在尝试以有序的方式显示我的所有表格行

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>

提前感谢您的所有帮助!如果这不是我想要完成的事情的方法,我愿意接受新的建议,再次感谢。

4

1 回答 1

0

为什么拿到数据后才下单?为什么不要求数据库返回已经排序的数据。

SELECT * id, ip_adress, visits, dates FROM u_visits ORDER BY id ASC

这就是 ORDER BY 的美妙之处,给它一个列索引和一个排序方向。

于 2013-09-01T05:43:32.173 回答