No biggie to set default value in a select box:
<option selected> MyOptionValue </option>
And for defaulting with a value from a database table ( here I read years from a table, and if the user record field edu_end_year gets a match I display that value as selected, if no match the default text is used ) :
<option value="default"> <?php echo $default_text_year ?> </option>
<?php while($option = $years->fetch_object()){ ?>
<option <?php echo $option->year == $record->edu_end_year ? 'selected' : ''?> value='<?php echo $option->year; ?>'> <?php echo $option->year ?></option> <?php } ?>
But I am stuck when it comes to combining the two in a code-efficient way. My question is this:
How do I set table record entry a default value only when there is no hit in the entries read from the user record? The value must come from the same table.
An example of implementation:
A user can select a favorite country from a list. When the user logs in the next time the favorised country should be shown as selected. If no favorite country was selected, the user's home country should be shown as selected.
I am stuck. Any and all help appreciated! Thanks!