View record in List/Menu

A

Anonymous

Guest
how to view a record in a List/Menu type (not text field)? i got the List/Menu already got recordset inside, but when it show up, i want it to show certain record first, but how? the current code for the List/Menu is:

<select name="category" id="category">
<?php
do {
?>
<option value="<?php echo $row_rsCategory['CategoryName']?>"><?php echo $row_rsCategory['CategoryName']?></option>
<?php
} while ($row_rsCategory = mysql_fetch_assoc($rsCategory));
$rows = mysql_num_rows($rsCategory);
if($rows > 0) {
mysql_data_seek($rsCategory, 0);
$row_rsCategory = mysql_fetch_assoc($rsCategory);
}
?>
</select>


this code is to list all the records in a table, but i want it to show certain record first, how? thanks
 
You can use the selected="selected" attribute in some option to make it the first one in the list.

If you want an ordered list... why don't you select them in the proper order when you make your query... before printing !?

Example:
Code:
mysql> SELECT name FROM kids ORDER BY name

// Expected: all names in Alphabetic order
 
i mean, if there is 10 records, i want to show the 3rd record first, how, can u show in the previous code i gave, thanks
 
You need to be more especific !
Anyway, here goes an example:
Code:
<?php

$result = mysql_query("... query...");

$row = mysql_fetch_array($result);
$nrows = mysql_num_rows($result);

print '<select name="category" id="category">';

for($i = 0; $i < $nrows; $i++){
   if($i < 3) { continue; }   
   print '<option value="' . $row['value'] . '">' . $row['name'] . '</option>' . "\n";
}

print '</select>';

?>
 
Back
Top