How can I use php to control the selected values in the select statement? For example, I have a select form & lt; select & nbsp; nameselect_1 & gt; & lt; option & nbsp; value & gt; & lt; option & gt; & lt; option & nbsp; valuevalue_1 & gt; option_1 & lt; option & gt; & lt; op how to use php to control the selected values in the select statement?
For example, I have a select form.
option_1option_2.....option_n
The last n may be very large. my design is to save the user form submitted to mysql, and then the user can edit it. on the editing page, this single-choice form must be displayed as a mysql value in the selected status. I have read the value in mysql $ value_select_1. how can I use php to control this select_1 form and select the value of $ value_select_1?
Soon after learning php, I hope I will not be enlightened.
Share: More
------ Solution --------------------
$value_select_1=1;
$select_arr=array('value_1','value_2','value_3','value_4');
foreach ($select_arr as $value){
if(intval(substr($value,-1,1))==$value_select_1)
echo $value.' selected';
}