0

我需要像上面那样进行输出,但是如何添加数字,我可以用 <ol> 做,但这不是我需要的,<ol> 标签给了我不同的顺序..知道如何制作这个并在链接之前添加数字?

1. Site.com      6. Site.com
2. Site.com      7. Site.com
3. Site.com      8. Site.com
4. Site.com      9. Site.com
5. Site.com     10. Site.com

这是php代码

<?
$list = $my_db->fetch("SELECT " . MY_PREFIX . "list.id, name,address, in_hits, out_hits FROM " . MY_PREFIX . "list LEFT JOIN " . MY_PREFIX . "sites ON " . MY_PREFIX . "list.id=" . MY_PREFIX . "sites.id WHERE status >0 AND status <3 ORDER BY in_hits DESC LIMIT 9");

$count = 1;

echo "<ul>";
foreach($list as $site) {;?>
<li><a href="<?php echo "/out.php?url=" . $site["address"];?>" target="_blank" rel="nofollow" title="<?php echo htmlentities(stripslashes($site["name"]));?>"><?php echo htmlentities(stripslashes($site["name"]));?></a></li>

<?
if ($count == 5) {echo "</ul><ul>";}
$count++;
}
echo "</ul>";
?>
4

3 回答 3

4

使用start属性

<ol start="6">
    <li>anything</li>
</ol>

或者您可以使用应用于一个有序列表的css(多列属性)

于 2013-01-14T15:56:33.507 回答
1

如何使用一些计数器:

<?
$list = $my_db->fetch("SELECT " . MY_PREFIX . "list.id, name,address, in_hits, out_hits FROM " . MY_PREFIX . "list LEFT JOIN " . MY_PREFIX . "sites ON " . MY_PREFIX . "list.id=" . MY_PREFIX . "sites.id WHERE status >0 AND status <3 ORDER BY in_hits DESC LIMIT 9");

$count = 1;
echo "<ul>";
foreach($list as $site) {;?>
<li><a href="<?php echo "/out.php?url=" . $site["address"];?>" target="_blank" rel="nofollow" title="<?php echo htmlentities(stripslashes($site["name"]));?>"><?php echo $count ?>. <?php echo htmlentities(stripslashes($site["name"]));?></a></li>

<?
if ($count % 5 == 0) {echo "</ul><ul>";}
$count++;
}
echo "</ul>";
?>

我也将行更改if ($count == 5)if ($count % 5 == 0). 所以每 5 行都会开始一个新的列表。

于 2013-01-14T16:03:57.127 回答
0

尝试类似的东西

foreach($list as $site) {;?>
<li><a href="<?php echo "/out.php?url=" . $site["address"];?>" target="_blank" rel="nofollow" title="<?php echo htmlentities(stripslashes($site["name"]));?>">

    <?php
    $i=1;
    $j=6
    if(count<=5){
    echo .$i.'.'.htmlentities(stripslashes($site["name"]));$i++;

    }else{
    echo .$j.'.'.htmlentities(stripslashes($site["name"]));$j++;
    }
    ?>
    </a></li>

其余代码保持不变

于 2013-01-14T16:01:42.917 回答