Setting default select value in php?

I want to update user datails with id .How i can set select element a default value from the database?

Normally while you’re running through the loop to retrieve each option for the select element, you would add the “selected” tag when you find the correct value.

while (row = fetch()) {
  $sel = "";
  if ($row[column]==id) $sel = "selected";
  echo "<option value=whatever ".$sel.">option name</option>";

what if we have only three option which is not from database?

How do you know which of those three options should be the default?

Just do it according to the data you have, the method is clear. If it’s different, handle it different?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.