What's wrong with this? I tried to translate it from ASP to PHP. echo '<option '; if int(letter_id) = int($row['letter_id']){ echo 'selected'; } echo ' value="'.$row['letter_id'].'"> Spoke '.$row['letter_id'].'</option>'."\n"; PHP: In ASP it would've been: <option <%if int(letter_id) = int(RS("letter_id")) then response.write "selected" end if%> value="<%=RS("letter_id")%>">SPOKE <%=RS("letter_id")%></option> Code (markup):
I convert to integers like this: $Number = 12.345; $newNumber = (int)$Number; echo "before: ". $Number; echo"<br>after: ". $newNumber; this will display: before: 12.345 after: 12 Let me know if that helps
That's not what intended. I have a database table where I'm retrieving the values into a dropdown. By then selecting from one of the dropdown selection it should write selected next to it.
This solved: echo '<option '; if (intval($letter_id) == intval($row['letter_id'])){ echo 'selected'; } PHP:
first up, the php if statement has to wrapped in ( )'s i.e if($number!='1'){ echo 'not a number 1'; }else{ echo 'this is a number 1'; } $sel=1; echo '<option '; if($sel==1 && intval($sel)){ echo 'selected'; } echo ' value="'.$sel.'" yadda yadda yadda'; have fun with that one