I have table "pages" and have 4 positions. My question is how I am going to show value of "5" on select option instead of showing all positions from 1 - 5.
Image Example:
Instead of
It should only show:
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>";
Thanks in advance. :)
Use the selected
attribute, e .g.
for($count=1; $count <= $page_counts + 1;$count++){
$selected = ($count == 5) ? ' selected="selected"' : '';
echo "<option value='{$count}'$selected>{$count}</option>";
}
So when $count hits 5, you'll get
<option value='5' selected="selected">5</option>
Check for last value of $count
and add selected
for($count=1; $count <= $page_counts + 1;$count++){
$sel = ($count == ($page_counts + 1)) ? ' selected="selected"' : '';
echo "<option value='{$count}'$sel>{$count}</option>";
}
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.