chaosuk Posted February 17, 2012 Share Posted February 17, 2012 Hi guys, using the code below within an admin panel to create a drop down allowing the user to select the profiles they wish to assign to the record they're creating, problem we have is that once a record is created, if they need to edit it for what ever reason the selected profile option isn't sticking. I've played around with lots of variants of if existing_record to try and get it add selected="selected" into the code but failed at every attempt, any advice gratefully received. <?php // List only breeder profiles in the database echo '<select name="profile" class="textinput noborder">'; echo '<option value="any">Any</option>'; $qryGetDistinctProfile = "SELECT * FROM profiles ORDER BY title ASC"; $resGetDistinctProfile = mysql_query($qryGetDistinctProfile,$connection) or die(mysql_error()); if(mysql_num_rows($resGetDistinctProfile) > 0){ $id = mysql_result($resProfile, 0, "id"); while ($row = mysql_fetch_assoc($resGetDistinctProfile)){ echo '<option value="'.$row['id'].'" >'.$row['title'].'</option>'; } } echo '</select>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/257171-select-distinct-if-existing/ Share on other sites More sharing options...
darkfreaks Posted February 17, 2012 Share Posted February 17, 2012 http://www.phpro.org/tutorials/Dropdown-Select-With-PHP-and-MySQL.html Quote Link to comment https://forums.phpfreaks.com/topic/257171-select-distinct-if-existing/#findComment-1318276 Share on other sites More sharing options...
chaosuk Posted February 17, 2012 Author Share Posted February 17, 2012 Thanks, but not working Getting the following error: Fatal error: Class 'DB' not found in on line 976 Quote Link to comment https://forums.phpfreaks.com/topic/257171-select-distinct-if-existing/#findComment-1318278 Share on other sites More sharing options...
darkfreaks Posted February 17, 2012 Share Posted February 17, 2012 http://stackoverflow.com/questions/1202712/mysql-database-config-in-a-seperate-class Quote Link to comment https://forums.phpfreaks.com/topic/257171-select-distinct-if-existing/#findComment-1318279 Share on other sites More sharing options...
chaosuk Posted February 17, 2012 Author Share Posted February 17, 2012 So as I'm already calling the config info via an include at the top of the page I'm guessing I can edit that row to remove the DB connection class? Quote Link to comment https://forums.phpfreaks.com/topic/257171-select-distinct-if-existing/#findComment-1318282 Share on other sites More sharing options...
darkfreaks Posted February 17, 2012 Share Posted February 17, 2012 you can edit the config info into the class yes. and just use that. Quote Link to comment https://forums.phpfreaks.com/topic/257171-select-distinct-if-existing/#findComment-1318284 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.