I have created three pull-downs for users to input their day, month and year of birth in a rego form. This is inserted into a MYSQL database as a single concatenated value called birthday. However, now when I want to create an update page which displays all the selected values in a form for editing, I can't figure out how to reverse concatenate the birthday variable so I can display the selected values in the pull-downs in the form for editing.

My code in the rego form:

<label>Birthday</label>				
<select style="width:50px;" name="day">
<option value="">Day</option>
<?php for ($i = 1; $i <= 31; $i++) : ?>
<option value="<?php echo ($i < 10) ? '0'.$i : $i; ?>"><?php echo $i; ?></option>
<?php endfor; ?>
</select>
<select name="month">
<option value="">Month</option>
<?php for ($i = 1; $i <= 12; $i++) : ?>
<option value="<?php echo ($i < 10) ? '0'.$i : $i; ?>"><?php echo $i; ?></option>
<?php endfor; ?>
</select>
<select name="year">
<option value="">Year</option>
<?php for ($i = 1900; $i < date('Y'); $i++) : ?>
<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
<?php endfor; ?>
</select>

Having a mental blank about how to use this in the form for editing...

    Treat the date as a string and take the respective substrings.

      laserlight's suggestion ([man]substr[/man] is the opposite of concatenation); or use [man]strtotime[/man] (which can read MySQL's string representation of a date field) and [man]date[/man]; or use MySQL's date/time functions to select the year, month, and day separately from the date field.

        Ah thanks guys. Got it working with your advice. 🙂

          Write a Reply...