I have a dropdown list that works fine, but halfway through the list of 80 values is the one I want as selected by default
$cosOptions = cos_options();
Is the variable
<td><select name="options"><?php print $cosOptions; ?></select></td>
Prints the dropdown, then the function below.
function cos_options()
{
$dbh = dbh_get();
$options = '';
$sql = 'select code, descr FROM cos';
$stmt = $dbh->prepare($sql);
$stmt->execute();
while (true) {
$r = $stmt->fetch();
if (is_bool($r)) break;
$options .= '<option value="' . $r['code'] . ' ' . $r['descr'] . '">' . $r['code'] . ' ' . $r['descr'] . '</option>';
}
dbh_free($dbh);
return $options;
}
The Postgres table only has two columns and 80 rows
code descr
D1 Pizza
D2 Bread
D3 Cornflakes etc,.
What I need is D43 Rice to be selected at first because 90% of the time it will be this. How can I achieve this? I've gone through a bunch of posts on here but can't get it working.