2012-09-24 79 views
1

我有表「頁」,並有4個職位。 我的問題是我會如何顯示上選擇選項「5」值,而不是顯示從1所有職位 - 5php - 顯示上一個值+ 1選擇>選項

形象的例子:

代替

enter image description here

它應該只顯示:

enter image description here

function get_all_arjay_pages_desc(){ 
    $query = "SELECT * 
       FROM pages 
       ORDER BY position DESC"; 
    $result = mysql_query($query); 
    validate_query($result); 

    return $result; 
} 


echo "<select name='position' id=''>"; 
     $get_all_page = get_all_arjay_pages_desc(); 
     $page_counts = mysql_num_rows($get_all_page); 

     for($count=1; $count <= $page_counts + 1;$count++){ 
      echo "<option value='{$count}'>{$count}</option>"; 
     } 

     echo "</select>"; 

在此先感謝。 :)

回答

0

檢查的$count最後一個值,並添加選擇

for($count=1; $count <= $page_counts + 1;$count++){ 
      $sel = ($count == ($page_counts + 1)) ? ' selected="selected"' : ''; 
      echo "<option value='{$count}'$sel>{$count}</option>"; 
} 
+0

正是!^_^ 你救了我的命.. – arjay0601

0

使用selected屬性,例如,

for($count=1; $count <= $page_counts + 1;$count++){ 
    $selected = ($count == 5) ? ' selected="selected"' : ''; 
    echo "<option value='{$count}'$selected>{$count}</option>"; 
} 

所以當$計數打5,你會得到

<option value='5' selected="selected">5</option> 
+0

會嘗試這一點。 謝謝。 – arjay0601

相關問題