bossman Posted August 31, 2009 Share Posted August 31, 2009 I am creating an admin for a project manager website. Each Project is a title and a link. The projects are organized by date, industry, and product. I am trying to make an add/edit/delete function for the projects. So far I have successfully gotten the add and delete functions to work. But now, I am stuck on the 'edit' page. I have gotten the page to pull in the title and link to the projects, but I am having a hard time getting the radio button to have automatically have what is in the database pre-selected. Right now im working with date, the options are 2006, 2007, 2008, and 2009. The database has a row called date, its TEXT(255). in the row it either has 2006, 2007, etc... Can anybody help me with a script that will pull in whatever the date is in the database and have it pre-populate my radio button? Link to comment https://forums.phpfreaks.com/topic/172569-load-mysql-data-into-radio-buttons/ Share on other sites More sharing options...
Psycho Posted August 31, 2009 Share Posted August 31, 2009 <?php //Set this variable to the value in the database //I hard code it here for example purposes $db_date = '2007'; //Create an array of all possible values //Or, if all possible values are stored in a list table from DB, get them there $dates = array('2006', '2007', '2008', '2009'); //Create the radio options $radio_opts = ""; foreach ($dates as $date) { $checked = ($date==$db_date) ? ' checked="checked"' : ''; $radio_opts .= "<input type=\"radio\" name=\"groupname\" value=\"{$date}\"{$checked}> {$date}<br />\n"; } //other code goes here as needed ?> //Form Select the date: <?php echo $radio_opts; ?> Link to comment https://forums.phpfreaks.com/topic/172569-load-mysql-data-into-radio-buttons/#findComment-909699 Share on other sites More sharing options...
bossman Posted August 31, 2009 Author Share Posted August 31, 2009 ok, that makes more sense to me. So...for this part.. $db_date = '2007'; I would replace that with... $db_date = $row['date']; ....correct? and then from there proceed with the rest of the code? Link to comment https://forums.phpfreaks.com/topic/172569-load-mysql-data-into-radio-buttons/#findComment-909704 Share on other sites More sharing options...
Psycho Posted August 31, 2009 Share Posted August 31, 2009 Yes. Link to comment https://forums.phpfreaks.com/topic/172569-load-mysql-data-into-radio-buttons/#findComment-909829 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.