doforumda Posted February 16, 2010 Share Posted February 16, 2010 how can we select date of birth from db and break it into three variables so year stores in $year month stores in $month and day stores in $day. i need this because i have a form with three select menus so when user clicks edit to edit his date of birth then it select dob from db put the current dob in those select menus. my form is below <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php session_start(); include("dbconnect.php"); $query = mysql_query("SELECT * FROM dob WHERE userid='$_SESSION[userid]'"); while($row = mysql_fetch_assoc($query)) { $date = $row['dob']; ?> <form id="form1" name="form1" method="post" action=""> Date of Birth: <select name="month" id="month"> <option value="Jan" SELECTED>Jan</option> <option value="Feb" >Feb</option> <option value="Mar" >Mar</option> <option value="Apr" >Apr</option> </select> <select name="day" id="day"> <option value="1" selected>1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select> <select name="year" id="year"> <option value="2010" selected>2010</option> <option value="2009">2009</option> <option value="2008">2008</option> </select> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/192268-how-select-data-from-table-and-place-it-in-html-form/ Share on other sites More sharing options...
premiso Posted February 16, 2010 Share Posted February 16, 2010 [ot]Why do you have a table of it's own for dob? Do you expect people to have multiple dob's? (Just Curious)[/ot] You need to provide us with more information, such as what data type is dob, is it a UNIX Timestamp, or a MySQL Date field? As this is needed to provide you with the correct answer. Quote Link to comment https://forums.phpfreaks.com/topic/192268-how-select-data-from-table-and-place-it-in-html-form/#findComment-1013218 Share on other sites More sharing options...
doforumda Posted February 16, 2010 Author Share Posted February 16, 2010 [ot]Why do you have a table of it's own for dob? Do you expect people to have multiple dob's? (Just Curious)[/ot] You need to provide us with more information, such as what data type is dob, is it a UNIX Timestamp, or a MySQL Date field? As this is needed to provide you with the correct answer. it is DATE field Quote Link to comment https://forums.phpfreaks.com/topic/192268-how-select-data-from-table-and-place-it-in-html-form/#findComment-1013225 Share on other sites More sharing options...
premiso Posted February 16, 2010 Share Posted February 16, 2010 list($year, $month, $day) = explode("-", $row['dob']); The MySQL Date format should be YYYY-MM-DD, so that should get you your variables. Quote Link to comment https://forums.phpfreaks.com/topic/192268-how-select-data-from-table-and-place-it-in-html-form/#findComment-1013230 Share on other sites More sharing options...
doforumda Posted February 17, 2010 Author Share Posted February 17, 2010 hi I am trying below code but it is not displaying date from database in select menus. the format of the date in mysql table is DATE here the value is 2008-04-04. code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php //session_start(); include("dbConnect.php"); $query = mysql_query("SELECT * FROM basicinfo_age WHERE userid='1'"); while($row = mysql_fetch_assoc($query)) { $date = $row['dob']; //echo $date; list($year, $month, $day) = explode("-", $date); //$years = $year; //$months = $month; //$days = $day; //echo $years; } ?> <form id="form1" name="form1" method="post" action=""> Date of Birth: <select name="month" id="month"> <option value="Jan" <?php if($month=="Jan") { echo "SELECTED"; } ?>>Jan</option> <option value="Feb" <?php if($month=="Feb") { echo "SELECTED"; } ?>>Feb</option> <option value="Mar" <?php if($month=="Mar") { echo "SELECTED"; } ?>>Mar</option> <option value="Apr" <?php if($month=="Apr") { echo "SELECTED"; } ?>>Apr</option> </select> <select name="day" id="day"> <option value="1" <?php if($day=="1") { echo "SELECTED"; } ?>>1</option> <option value="2" <?php if($day=="2") { echo "SELECTED"; } ?>>2</option> <option value="3" <?php if($day=="3") { echo "SELECTED"; } ?>>3</option> <option value="4" <?php if($day=="4") { echo "SELECTED"; } ?>>4</option> </select> <select name="year" id="year"> <option value="2010" <?php if($year=="2010") { echo "SELECTED"; } ?>>2010</option> <option value="2009" <?php if($year=="2009") { echo "SELECTED"; } ?>>2009</option> <option value="2008" <?php if($year=="2008") { echo "SELECTED"; } ?>>2008</option> </select> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/192268-how-select-data-from-table-and-place-it-in-html-form/#findComment-1013520 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.