【问题标题】:Add Numbers to MySQL, HTML table in order [closed]按顺序将数字添加到 MySQL、HTML 表 [关闭]
【发布时间】:2016-05-17 21:34:10
【问题描述】:

我会尽力解释我想要做什么。希望你能帮助我。我有一个包含链接的数据库,这些链接显示在表格中。我按点的顺序正确输出了条目,但我试图在侧面添加一个排名数字,所以它在每个条目的页面上显示 1、2、3、4 等。 这是我的尝试。

<table width = "1000" style='table-layout:fixed;'>
    <tr>
        // These are the numbers I need to add
        <th>Rank</th>
        // All these work fine.
        <th>Host</th>
        <th>Location</th>
        <th>Points</th>
    </tr>
        <?php while($row1 = mysqli_fetch_array($result1)):;?>
    <tr>
        <td><?php echo $row1[0]; ?></td>
        <td><a href="<?php echo $row1['Location']; ?>"><?php echo $row1[1]; ?></a></td>
        <td><?php echo $row1[2]; ?></td>
    </tr>
        <?php endwhile; ?>
</table>

希望您能理解我想要做什么,如果您需要更多信息,请告诉我。 感谢您的宝贵时间。

【问题讨论】:

  • 您需要在 SELECT 或 for 循环中“计数()”。祝你好运。
  • 您需要养成accepting answers 的习惯,它可以帮助您解决问题。您将获得积分,并鼓励其他人帮助您。你知道,那个stackoverflow.com/q/37244399 ;-)
  • @Saty 看到你对 的评论“在 while($row1 = mysqli_fetch_array($result1)):; (在现在已删除的答案中)。是的,这就是我在他们的另一个问题 stackoverflow.com/q/37244399 中所说的,但他们仍然说它有效。哈,是的。所以我认为我们都被拖了。
  • 我觉得我们受到了攻击,因为向循环中添加递增索引有多难。 `$i++;回声 $i; `
  • @Wobbles 我想说你是在钱上 ;-) 关于你评论的开头。

标签: php html mysql


【解决方案1】:

你的意思是? :

<?php $rankId=0; while($row1 = mysqli_fetch_array($result1)){ ?>
  <tr>
    <td><?=$rankId++ ?></td>
    <td><?=$row1[0] ?></td>
    <td><a href="<?=$row1['Location'] ?>"><?= $row1[1] ?></a></td>
    <td><?=$row1[2] ?></td>
  </tr>
<?php } ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多