wwfc_barmy_army Posted November 6, 2006 Share Posted November 6, 2006 Hello.I think this is in the right sectionI use this php code to get the records from a database and put them in a drop down box:[code=php:0]<?php$result = @mysql_query("SELECT * FROM artist"); echo "<select name='artists'>";while ($row = mysql_fetch_assoc($result)) { echo " <option value='{$row['artist_id']}'>{$row['name']}</option>";}echo "</select>";print $row;?>[/code]Is there a way to make it so that the drop down box has the last entered name field (the highest artist_id) as it's default selected field?So if i entered:ID Name1 Red2 Bluewhen i loaded up the page with the dropdown box on it would already have blue selected as default but i could if i wanted select Red, so if it then changed to:ID Name1 Red2 Blue3 GreenWhen i loaded up the page with the dropdown box it would have green selected by default but i could choose Red, or blue if i wanted to.Is this possible?Thanks Quote Link to comment Share on other sites More sharing options...
trq Posted November 6, 2006 Share Posted November 6, 2006 Of course its possible, but, and Im sorry if this sounds harsh, but if your going to learn to program your going to need to learn to think a problem through.You can change the order your query returns results by using an ORDER BY clause. You can then use some html to select the first or last record. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.