-3

I'm trying to make a select list with options from a MySQL database with PHP remember the last imput. I've learned here how keep the value's in a form after submit with php (second answer) which worked on a select with Yes/No options.

Now i am trying to implement this into the select that has generate options. After i got errors with if-statements I learned here i can use Ternary operators to fix the problem but it does not seem to work. I keep getting errors like --parse error, unexpected '.'--

My code is:

<select name="reeks" onchange="this.form.submit()">
  <option value= "0" style="display:none;" selected="" disabled=""> Reeks </option>
  <?php 
    $sql = "SELECT * FROM reeks";

    $result = (mysql_query($sql));

    while ($row = mysql_fetch_array( $result )){
        $reeks = $row['reeks'];
        echo '<option '. ($_GET['reeks'] == 'ja') ? .'selected="'. $reeks. '" '. ; .' name="reeks">'. $reeks . '</option>';
    }
  ?>
</select>

This is what the code looks like for the Yes/No select

<option <?php if ($_GET['reeks'] == ''. $reeks. '') { ?>selected="'. $reeks. '" <?php }; ?> name="reeks" value="ja">Ja</option>
Community
  • 1
  • 1
Martey
  • 1
  • 6
    Proper syntax for ternary operator includes `:` I don't see it in your code. – u_mulder Aug 17 '15 at 13:44
  • 2
    If you're still stumbling over syntax errors, the ternary comparison is the last thing you want to introduce. – mario Aug 17 '15 at 13:46

1 Answers1

0
<option <?php if ($_GET['reeks'] == ''. $reeks. '') { ?>selected="'. $reeks. '" <?php }; ?> name="reeks" value="ja">Ja</option>

should be -

<option <?php $_GET['reeks'] == ''.$reeks.'' ? echo 'selected=" '. $reeks. '" : else_part_comes_here; ?> name="reeks" value="ja">Ja</option>
Rachitta A Dua
  • 358
  • 1
  • 11
  • 2
    A little explanation might be helpful. What's the problem, what's your solution, and how does it solve the problem? – showdev Aug 17 '15 at 22:08