i am trying to retrieve date from Mysql db to my html form in order to edit the records, now the way i used to insert the date into the database was getting Year – Month – Day each from a list and then unite them in one variable like this :
$dob = $_POST['Year'] . '-' . $_POST['Month'] . '-' .$_POST['Day'];
this will insert the value of $dob like this format 0000-00-00 in my table
the problem is that how i will retrieve this variable and split it each element to its specific list
what i tried seems useless and wrong which is this code
$row['userDateOfBirth'] = $year . '-' . $month . '-' . $day ;
then put each variable to (example:year)
<option value="1920" selected="selected"><? echo $year ; ?></option>
this did not work , how can i do this ?
Assuming you’ve got an actual date/datetime field, you can do the splitting inside MySQL:
which gives you three separate fields containing the individual date components. You could also do things like
explode('-', $datestr)in PHP to decompose ‘yyyy-mm-dd’ into individual yyyy, mm, and dd chunks.Lots of options, it’s up to you to pick which one is easiest/best for your particular problem.