2013-02-06 72 views
0

我的index.php文件:有序列表重複號1個

<?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'。這裏有什麼問題?

+1

請修復您的sql語法:SELECT'pic_id','top','left' FROM image_tag ORDER BY'pic_id'「。 – andrew

+0

當你在這裏時,請注意'mysql *'庫使用是[棄用](http://www.php.net/manual/en/function.mysql-query.php) – Nanne

回答

2

您隨時用<ol></ol>重新開始您的訂單清單。修復,你應該有結果是這樣的:

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

這樣做,把你的<ol></ol>標籤while循環之外。

1

你把<ol></ol>每次都放在那裏。你不應該

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

'$ top'沒有意義的地方,你使用它... – Nanne

+0

謝謝,我解決了這個問題。 –

0

把你<ol>出方while循環

請檢查你的代碼的這一部分,

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

我猜你應該使用*在查詢

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> 

這應該是訣竅。您每次創建一個新的有序列表。