选中的回声选项值

Im tryin to fix when i press my search button. That the selected search from my option field remains selected. But at the moment it automaticly picks the first field of the options in my form.

First one is hardcoded and it works.

<option value="HS" <?= ($nickval == 'HS' ? 'selected="selected' : '')?>>Homer Simpsons</option>

But then i wanted to echo out option value from database so its not hardcoded.

<?php
while(db2_fetch_row($queryexe)) {
 echo "<option value='$pin'>$fullname</option>";
}
?>   

And now when i want to add if its selected i tried to solve it like this.

echo "<option value='$pin'($nickval == '$pin' ? 'selected='selected'' : '')>$fullname </option>";

This is how i get my pin

 $pin = db2_result($queryexe, 'P510PIN');

This is how i get my $nickval

 $nickval = $_GET["int"];

Any suggestions what im doin wrong? Sorry if im unclear but i've tried my best

Aside from quoting errors indicated in the syntax highlighting...

You're trying to execute PHP code inside of a string:

echo "<option value='$pin'($nickval == '$pin' ? 'selected='selected'' : '')>$fullname </option>";

Variable interpolation is one thing, but code inside of a string isn't going to automatically execute. It's just a string being echoed to the page. (Check the page source and see what's actually being emitted to the browser.)

Separate the strings from the code which builds the strings:

echo "<option value='$pin' " . ($nickval == $pin ? "selected='selected'" : "") . ">$fullname </option>";