I am trying to load a drop down option values based on database information. I have the following code and its working fine but I don’t know how to code in the following to show the selected value.
$output = null;
foreach ($records->result() as $row) {
$output .= "<option value='".$row->sub_category_id."'>".$row->sub_category_name."</option>";
}
return $output;
I know I should be using something like following, but I can’t understand how to put the following code together with the above codes.
if ($row->sub_category_id == $sub_category_id) {select="selected"}
Could you please show me?
thanks 🙂
You almost finished it correctly. here you go: