0

我在 HTML 表中使用 php 显示来自 Mysql 表的数据,但我需要另外 2 件事情来完成表:

1-如何为表格行交替颜色以使用 4 个不同的 css 类,我现在正在使用 class='success' 我还有 3 个要使用,每个应该应用于每个表格行,怎么做?任何简单的例子,比如循环之类的?

2-数据从表中最旧的记录显示到最新记录,我想显示相反的,所以最后一条记录首先显示在 html 表中。

我的这张表的代码:

<?php echo "<table class='table'>
            <thead>
              <tr>
                <th>Order#</th>
                <th>Name</th>
                <th>Total</th>
                <th>Submitted On</th>
                <th>Status</th>
              </tr> </thead>"; 

                    while($row = mysqli_fetch_array($result))
                      {
                      echo "<tr class='success'>";
                      echo "<td>" . $row['lite_order_id'] . "</td>";
                      echo "<td>" . $row['lite_item_name'] . "</td>";
                      echo "<td>" . $row['lite_email'] . "</td>";
                      echo "<td>" . $row['lite_country'] . "</td>";
                      echo "<td>" . $row['lite_order_total'] . "</td>";
                      echo "</tr>"; }
             echo "</table>"; ?>
4

2 回答 2

0

1 - 使用id属性来设置单个元素的样式。在这里查看

2 - 在您的 MySQL 查询中,使用ORDER BY

(我想你id这里有一个专栏)

$query = "SELECT * FROM `yourtable` ORDER BY `id` ASC";

这里

于 2013-05-10T09:32:04.623 回答
0

要获取反向记录,您可以使用 mysql ORDER BY 子句或 PHP 函数 array_reverse()

于 2013-05-10T09:34:22.297 回答