View record in List/Menu

Links for php scripts

Moderators: macek, egami, gesf

kiwi
New php-forum User
New php-forum User
Posts: 124
Joined: Sun Feb 29, 2004 6:26 am
Contact:

View record in List/Menu

Postby kiwi » Sun Sep 12, 2004 7:20 am

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

User avatar
gesf
Moderator
Moderator
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Postby gesf » Sun Sep 12, 2004 8:59 pm

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: Select all

mysql> SELECT name FROM kids ORDER BY name

// Expected: all names in Alphabetic order

kiwi
New php-forum User
New php-forum User
Posts: 124
Joined: Sun Feb 29, 2004 6:26 am
Contact:

Postby kiwi » Mon Sep 13, 2004 6:29 pm

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

User avatar
gesf
Moderator
Moderator
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Postby gesf » Tue Sep 14, 2004 8:23 pm

You need to be more especific !
Anyway, here goes an example:

Code: Select all

<?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>';

?>


Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests

cron