Please help with tricky array question
Hi All,
I have created a page to update an event record and I'm trying to
populate the drop-down option list for $months with the value stored in
the record. I have created a $mysqldate array to separate the different
elements of the date as stored in the table, for insertion into the
various parts of the form. For brevity sake, I'm not showing all of the
code.
> $months =
> array('Jan','Feb','Mar','Apr','May','Jun','Jul','A ug','Sep','Oct','Nov','Dec');
> $mysqldate = explode('-', $row_getEvents['event_date']);
> <select name="month" id="month">
> <?php for ($i=1;$i<=12;$i++) { ?>
> <option value="<?php echo $i <10 ? '0'.$i : $i; ?>"
> <?php echo ' selected="selected"'; ?>><?php echo
> $months[$i-1]; ?> </option>
> <?php } ?>
> </select>
> <label for="day">Date:</label>
> <input type="text" name="day" id="day" size="2" maxlength="2"
> value="<?php echo $mysqldate[2]; ?>" />
> <label for="year">Year:</label>
> <input type="text" name="year" id="year" size="4"
> maxlength="4" value="<?php echo $mysqldate[0]; ?>"/>
The problem is I can't figure out how to take the value $mysqldate[1]
(which is the value for month) and have it display as the default month
for this record, while still having all months available in the
drop-down. The code as I have it includes all months, but the default
is Dec. I have changed <?php echo $months[$i-1]; ?> to this <?php echo
$months[$mysqldate[1]-1]; ?> and get the correct month as default, but
that turns all twelve options into the same month, e.g. twelve Aug's. I
probably need a conditional statement, but I don't know what the
condition is or should be. So how do I set the record's month as the
default choice, while preserving the other eleven choices in the
drop-down list?
TIA
Brett
|