hello everyone,
I am making a job portal site. the job seeker in my site enters his date of birth by using three drop down lists (date,month,year). this value i concatenate and insert into database as (1990-09-28). when the user presses the edit button , i want to retrieve this date and display in the drop down list. i first explode the string value i recieve from database into an array. so i have values like :
$datearray[0]=>1980
$datearray[1]=>09
$datearray[2]=>28
now i want the same values to appear selected in my drop down list. I have made a function make_date_list(),and i use it for displaying the drop down list of date where i want. i dont want to use the if condition for it will be very long code.
please forward any suggestions.
phoenixfire2
0
Newbie Poster
Recommended Answers
Jump to Posttry:
<?php $datearray=explode('-','1980-09-28'); $days=str_replace('>'.$datearray[2],' selected="selected">'.$datearray[2],preg_replace('#option>(\d+)#','option value="$1">$1','<option>'.implode('</option><option>',range(1,31)).'</option>')); echo '<select name="day">'.$days.'</select>'; ?>
Jump to PostYou have to be careful with this as displaying, say:
2008 | 03 | 30 in a dropdown is fine, but then if somebody changes 03 to 02, the date becomes invalid.
Also you need to check leap years in order to include 29th Feb.
This should be done whenever …
All 7 Replies
hielo
65
Veteran Poster
phoenixfire2
0
Newbie Poster
diafol
phoenixfire2
0
Newbie Poster
diafol
hielo
65
Veteran Poster
phoenixfire2
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.