carpenma Posted January 5, 2010 Share Posted January 5, 2010 So I've got a form that looks for data in my database and based off of what it finds makes that information the default selected choices in my text areas and radio button sets. This has worked well so far but now I've got a few drop down lists that I want to automatically have the values from the database selected. I have the database info all put into the page and variables have been assigned. I could do a massive collection of if statements to get the desired effect but I know there has to be an easier way. If you need any more info I will be glad to provide it. Thank you very much. Link to comment https://forums.phpfreaks.com/topic/187202-select-statement-help/ Share on other sites More sharing options...
The Little Guy Posted January 5, 2010 Share Posted January 5, 2010 do you have some sample code? Link to comment https://forums.phpfreaks.com/topic/187202-select-statement-help/#findComment-988571 Share on other sites More sharing options...
jamkelvl Posted January 5, 2010 Share Posted January 5, 2010 Perhaps you should try a select statement? Or a loop? Hard to say as I am unclear as to what you're trying to do? Nor do I see any code... Link to comment https://forums.phpfreaks.com/topic/187202-select-statement-help/#findComment-988584 Share on other sites More sharing options...
carpenma Posted January 5, 2010 Author Share Posted January 5, 2010 There isn't really any code to show. It's just a standard select statement that goes with any dropdown list. I just need to know how to get the "selected" attribute next to the right choice without making as many if statements as there are choices. Link to comment https://forums.phpfreaks.com/topic/187202-select-statement-help/#findComment-988589 Share on other sites More sharing options...
trq Posted January 5, 2010 Share Posted January 5, 2010 Quite simple assuming your creating your <options> within a loop. As an example..... // while($row = ....) { echo "<option value={$row['name']}" . ($row['selected'] == 1) ? " selected='selected'" : "" . ">{$row['name']}</option>"; //} end while Link to comment https://forums.phpfreaks.com/topic/187202-select-statement-help/#findComment-988604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.