i have some options on a form that i want to be selected when the page loads depending on database value but i also want it to return all the other values for the col.
i had this idea.
function status ($status)
{
if ($status == $status)
{
$line = '<option value="'.$status.'" selected>'.$status.'</option>';
} else {
$line = '<option value="'.$status.'">'.$status.'</option>';
}
return $line;
}
problem being it does not return all the other values.
will i have to query the database each time to return each distinct value of the col to generate the rest of the options?
Yes, you’ll need to do a query to return each of the options that you want to populate the list with.
Note that in the function above you’re comparing $status and $status, which will not end well. You could make it less complex using the ternary operator: