我有HTML代码:
<select name="interest"> <option value="SEO">SEO и Блоговодство</option> <option value="auto">Авто</option> <option value="business">Бизнес</option> <option value="design">Дизайн</option> ...
在变量$result [‘interest’]中保存值.如何在value = $result [‘interest’]中设置元素选项?
谢谢!
解决方法
手动方式…..
<select name="interest"> <option value="SEO"<?PHP if($result['interest'] == 'SEO'): ?> selected="selected"<?PHP endif; ?>>SEO и Блоговодство</option> .....
更好的方法是循环利用
$interests = array( 'SEO' => 'SEO и Блоговодство','auto' => 'Авто',.... ); <select name="interest"> <?PHP foreach( $interests as $var => $interest ): ?> <option value="<?PHP echo $var ?>"<?PHP if( $var == $result['interest'] ): ?> selected="selected"<?PHP endif; ?>><?PHP echo $interest ?></option> <?PHP endforeach; ?> </select>