PHP Option Dropdown set Option to One Stored in DB

前端 未结 2 1572
忘了有多久
忘了有多久 2021-01-26 11:42

I have a PHP form which I use to edit a record in the MySQL data base and it has a drop down list of values I would like to set the option that is held in the database to be the

2条回答
  •  醉酒成梦
    2021-01-26 11:50

    You could use

    while($row = mysql_fetch_assoc($result)){
        $selected = "";
        if($row['id'] == $curValue){
            $selected = "selected=\"selected\"";
        }
        echo " 
    }
    

    After you've updated your question, it seems MattP's answer suits your situation better.

提交回复
热议问题