How can PHP be used to preselect an option in a combo box based on a database value when editing a record?

When editing a record in a form, we can use PHP to preselect an option in a combo box based on a database value by comparing each option with the database value and adding the 'selected' attribute to the matching option. This way, the correct option will be preselected when the form is loaded for editing.

```php
<select name="category">
    <option value="1" <?php echo ($row['category'] == 1) ? 'selected' : ''; ?>>Option 1</option>
    <option value="2" <?php echo ($row['category'] == 2) ? 'selected' : ''; ?>>Option 2</option>
    <option value="3" <?php echo ($row['category'] == 3) ? 'selected' : ''; ?>>Option 3</option>
</select>
```

In this code snippet, `$row['category']` represents the database value for the category field of the record being edited. The `selected` attribute is added to the option that matches the database value, ensuring that it is preselected in the combo box.