How can I 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.
Reply to discussion (solution)
The data in the database is to take the value 1 when the saved data is output, and then determine whether the value is equal when the foreach output, that is, selected.
The data in the database is to take the value 1 when the saved data is output, and then determine whether the value is equal when the foreach output, that is, selected.
The moderator gave me a remote Chin.
My environment is not working yet !!!!
The data in the database is to take the value 1 when the saved data is output, and then determine whether the value is equal when the foreach output, that is, selected.
Niu
$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';}
$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';}
Thanks to the moderator. why is it-1 to 1?
$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';}
Thanks to the moderator. why is it-1 to 1?
If you understand, take the last one. thank you!
'; Echo''; For ($ I = 1; $ I <= 10; $ I ++) {echo'Option _ '. $ I .'';} Echo''; $ Cur = 10; echo'