CodeIgniter Forums
Code does not seem to work? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Code does not seem to work? (/showthread.php?tid=7464)



Code does not seem to work? - El Forum - 04-10-2008

[eluser]Tom Glover[/eluser]
I have a clients website, in which I need it to write a form from and array.

In the view file:
Code:
<select name="relayletter2" id="relayletter">
            &lt;? if (is_array($letters)){
                  foreach ($letters as $letter)
                 {
                     if($letter === $selected)
                        {?&gt;
                        <option selected="selected" value="&lt;?=$letter?&gt;">&lt;?=$letter?&gt;</option>
                      &lt;?  }else{ ?&gt;
                           <option value="&lt;?=$letter?&gt;">&lt;?=$letter?&gt;</option>
                   &lt;?  }
                    }
                }?&gt;        
              </select>

The array that is passed to it:
Code:
$letters = array('a','b','c','d','e','...')

It is meant to compare that to what it is getting for the database, and when it finds a match it is meant to set the option selected.

At the Moment all options are selected.


Code does not seem to work? - El Forum - 04-10-2008

[eluser]Thoer[/eluser]
What does the good ol' var_dump test say? Smile


Code does not seem to work? - El Forum - 04-10-2008

[eluser]MadZad[/eluser]
Plus, can change this line
Code:
<option selected="selected" value="&lt;?=$letter?&gt;">&lt;?=$letter?&gt;</option>
to
Code:
<option selected="selected" value="&lt;?=$letter?&gt;">letter=&lt;?=$letter?&gt;, selected=&lt;?= $selected ?&gt;</option>
for further enlightenment.