• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Weird comparison results using set_select - probably PHP's fault

#1
[eluser]mattpointblank[/eluser]
Hi all.

My application has three <select> boxes for choosing time - hours / minutes / AM or PM.

I'm reading each of these values back out of the database and want to set the boxes to their appropriate values if they were already set.

My code looks like this:

Code:
<select name="startTimeHours">
    <option value="01" &lt;?php echo set_select('startTimeHours', '01', @$StartTimeHours == 01); ?&gt;>01</option>
    <option value="02" &lt;?php echo set_select('startTimeHours', '02', @$StartTimeHours == 02); ?&gt;>02</option>
// etc
</select>

This code is meant to work when adding a new record as well as editing an existing one (hence the somewhat-hacky @ sign preceding the variable). When editing it works fine, it selects the correct row. When adding a new row, however, the form comes with '09' in the Hours dropdown pre-selected. Since $StartTimeHours doesn't exist when adding a new row (trying to echo it produced an error), I don't know why the code has decided that it's equal to '09'.

Does anyone have any idea?

#2
[eluser]mattpointblank[/eluser]
Never mind, got it. Changed the third parameter of set_select from:
Code:
set_select('startTimeHours', '01', @$StartTimeHours == 01)
to
Code:
set_select('startTimeHours', '01', @$StartTimeHours == '01')


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.