有序列表重复1号

时间:2013-02-06 08:42:41

标签: php html

我的index.php文件:

    <?php
$query = mysql_query("SELECT `pic_id` FROM image_tag ORDER BY `pic_id`");

    while($run = mysql_fetch_array($query)){
    $pic_id = $run['pic_id'];
    $left = $run['left'];
    $top = $run['top'];
?>

<div id = "taggednum" style = "top:<?php echo $top; ?>; left:<?php echo $left; ?>;">
<ol><li rel ="<?php echo $pic_id; ?>"></li></ol>
</div>

<?php
    }
?>

列表中没有显示正确的数字。整个列表的编号为“1”。这有什么问题?

5 个答案:

答案 0 :(得分:2)

您使用<ol></ol>始终重新启动订单列表。要修复,你应该有这样的结果:

<ol>
   <li>item 1
   <li>item 2
</ol>

要执行此操作,请将<ol></ol>标记放在while循环之外。

答案 1 :(得分:1)

您每次都会将<ol></ol>放在那里。你不应该

答案 2 :(得分:0)

<div id = "taggednum">
    <ol><?php
    $query = mysql_query("SELECT `pic_id`, `left`, `top` FROM image_tag ORDER BY `pic_id`");

        while($run = mysql_fetch_array($query)){
            $pic_id = $run['pic_id'];
            $left = $run['left'];
            $top = $run['top'];
            ?><li style="top:<?php echo $top; ?>; left:<?php echo $left; ?>;" rel="<?php echo $pic_id; ?>"></li><?php
        }
    ?></ol>
</div>

答案 3 :(得分:0)

<ol>放在while循环

请检查代码的这一部分,

$left = $run['left'];
$top = $run['top'];

我猜您应该在查询中使用*

答案 4 :(得分:0)

<div id = "taggednum">

<ol>
<?php
$query = mysql_query("SELECT `pic_id` FROM image_tag ORDER BY `pic_id`");

    while($run = mysql_fetch_array($query)){
    $pic_id = $run['pic_id'];
    $left = $run['left'];
    $top = $run['top'];
?>


<li rel ="<?php echo $pic_id; ?>" style = "top:<?php echo $top; ?>; left:<?php echo $left; ?>;"></li>


<?php
    }
?>
</ol>
</div>

这应该可以解决问题。您每次创建新的有序列表时都会创建。