3
votes
$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'];

What is wrong with this part of code .($i1 == $entry_id_selector_topic) .'? "selected" : ""

Default value is = Equals

For example, user select > Is greater than then click on Post button, page reloads. I expect that in drop down menu is selected and displayed value > Is greater than hovewer selected is default value.

Changed to this .($i1 == $entry_id_selector_topic) .'? selected="selected" : "">' Get always selected last item from array ∌ Does not contain

Update. Finally get solution. At first did not understand why $entry_id_selector_topic[0] does not allways displays the first item from $options1.

But when I choose some value from drop down menu and click submit button, $entry_id_selector_topic = $_POST['entry_id_selector']; the only value that exists is the value I chose from drop down menu. So in $entry_id_selector_topic there is new array with the only item [0].

Seems now the question is clear.

3

3 Answers

2
votes

This code works

echo '<td><select name="entry_id_selector[]" onmousedown="SetWidthToAuto(this)">';
foreach ( $options1 as $i1=>$opt1 ) : 
echo '<option value="' .$i1 .'"'
.(($i1 == $entry_id_selector_topic[0])? 'selected' : "") .'>'
.$opt1 .'</option>';
endforeach;
echo '</select></td>';

Only I have no explanations regarding $entry_id_selector_topic[0]

1
votes

i think that it should be:

($i1 == $entry_id_selector_topic)?"selected" : ""

if that condition is true it will return "selected" otherwise it will return "" .

1
votes
  echo '<option value="'.($i1 == $entry_id_selector_topic) ? "selected" : "".'>'.$opt1 .'</option>';

try this