简体   繁体   中英

Ordered list repeats number 1

my index.php file:

    <?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
    }
?>

It doesn't show the correct number on the list. It numbered '1' for the entire list. What is the problem here?

You restart your order list all the time with <ol></ol> . to fix, you should have the result like this:

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

to do so, put your <ol> and </ol> tags outside of the while loop.

You put your <ol> and </ol> in there every time. You shouldn't

<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>

put your <ol> out side while loop

Please check this portion of your code,

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

I guess you should use * in your query

<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>

This should do the trick. You are creating each time a new ordered list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM