PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am making a simple form and for some reason when I click to "Edit" a record it displays all the information previously entered in the "text" fields but it does not pull the ones for the drop down boxes.
All information flows very good as far as adding/deleting/editing but if you want to edit the records you have to remember what the previous values were, which is quite important because we use the system to upgrade meaning we have to know what you had so we can give you the next step up.
I am encountering some problems, the code looks like it would pull all the information from the database right? I need something to bring the current value from the database but to also give the remainder options from the code.
<option value="$current_value_on_database" selected>$current_value_on_database</option>
(Note: then values not on the database)
<option value="value">value</option>
<option value="value">value</option>
<option value="value">value</option>
//keys are put as value attribute, value part is put as text of option
$Opts = array(1=>"One", 2=>"Two", 3=>"Three", 4=>"Four", 5=>"Five");
//Output the combo-box with given options...
print "<select name='opts'>";
writeOpts($Opts, $selOpt); //$selOpt is the selected option that you ertrieve from db
print "</select>";
///////////////////////
//$aOpts is an array of Options
//$sSelect is the key of selected option
function writeOpts($aOpts, $sSelect = '')
{
echo "<option value=''".($sSelect==''?' selected':'').">-Select-</option>\r\n"; //comment this if you dont want a default -select- option
foreach ($aOpts as $val=>$text)
echo "<option value=''{$val}".($sSelect==$val?' selected':'').">{$text}</option>\r\n";
}