【发布时间】:2013-06-22 09:36:56
【问题描述】:
$options1 = array( 1=>'= Equals', '≠ Does not Equal', '> Is greater than', '≥ Is greater than or equal to', '< Is less than', '≤ Is less than or equal', '∋ Contains', '∌ Does not contain');
<select name="entry_id_selector[]">';
foreach ( $options1 as $i1=>$opt1 ) :
echo '<option value="' .$i1 .'"'
.($i1 == $entry_id_selector_topic) .'? "selected" : "">'
.$opt1 .'</option>';
endforeach;
echo '</select>';
$entry_id_selector_topic = $_POST['entry_id_selector'];
这部分代码有什么问题.($i1 == $entry_id_selector_topic) .'? "selected" : ""
默认值为= Equals
例如,用户选择> Is greater than 然后点击发布按钮,页面重新加载。我希望在下拉菜单中选择并显示值> Is greater than hovewer selected 是默认值。
更改为 .($i1 == $entry_id_selector_topic) .'? selected="selected" : "">' 始终从数组 ∌ Does not contain 中选择最后一项
更新。最后得到解决方案。起初不明白为什么$entry_id_selector_topic[0]
并不总是显示来自$options1 的第一项。
但是当我从下拉菜单中选择一些值并单击提交按钮时,$entry_id_selector_topic = $_POST['entry_id_selector']; 唯一存在的值是我从下拉菜单中选择的值。所以在$entry_id_selector_topic 中有一个新数组,其中只有一个项 [0]。
现在看来问题很清楚了。
【问题讨论】:
标签: php