So, I would like a select to auto-populate the dropdown's "Yes" selection, or alternatively, the "No". The returned value from a database query will be used to evaluate which dropdown will be selected.
I have thought since it's a true/false auto-population to just write 2 conditionals, but I thought there would be a better (read: less messy code) way to write code that would auto-populate the right selection from the drop down, based on the result from the database.
The base of the code I'm trying to write would be checking the variable against all of the selects, then appending a string that would select that drop down for the user in the view.
My question would be is there a simpler way to do this, instead of writing conditionals for each possible drop down value?
Code by request, written in CodeIgniter PHP:
$this->db->select('row');
$result = $this->db->get('table');
// This just selects and returns the values. This code does work, I'm just looking for a better way to do this task that someone might know, because I'm going to have drop downs with hundreds of possibilities, of which, I want the predefined one to be selected.
// Assume $result->row = "Yes"
if ( $result = "Yes" ) {
#Code for echo'ing radio button with "Yes" selected
}
else {
#Code for echo'ing radio button with "No" selected
}