TomT Posted October 7, 2009 Share Posted October 7, 2009 Hi I'm pulling some data from a DB and presenting it in a drop down list: <option> 1 </option> <option> 2 </option> <option> 3 </option> Etc.. This works well. I decided to set one of the options as Selected using: if ($user===$id) { echo "<option selected"; } else { echo "<option"; } echo " value='$id'>$name</option>"; This works but is VERY slow.. presumably as it has to check each $user against each $id.. Any way to do this faster ?? Thanks Link to comment https://forums.phpfreaks.com/topic/176816-dynamic-drop-down-list/ Share on other sites More sharing options...
vbnullchar Posted October 7, 2009 Share Posted October 7, 2009 <?php // start loop $selected = ($user===$id) ? 'selected' : ''; echo "<option value='$id' $selected>$name</option>"; // end loop ?> Link to comment https://forums.phpfreaks.com/topic/176816-dynamic-drop-down-list/#findComment-932257 Share on other sites More sharing options...
TomT Posted October 7, 2009 Author Share Posted October 7, 2009 Thanks that works.. But doesn't seem any faster ! ? Any way to speed things up ? Link to comment https://forums.phpfreaks.com/topic/176816-dynamic-drop-down-list/#findComment-932267 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.