php - Retrive a date from a database in three dropdown list -
i need retrive date database in 3 dropdown lists. mysql & php code:
if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); } else { $sql = "select ui.`sex` ui_sex , ui.`last_name` ui_lname, ui.`first_name` ui_fname, ui.`nickname` ui_nickname, ui.`nin` ui_nin, ui.`birth_date` ui_birth, ui.`userid` = 1"; $result = mysqli_query($con, $sql); $count = mysqli_num_rows($result); if ($count == 0) { echo '<h4>no data submited yet.</h4>'; } else{ while ($row = mysqli_fetch_array($result)) { $ui_sex = $row['ui_sex']; $ui_nume = $row['ui_lname']; $ui_prenume = $row['ui_fname']; $ui_nickname = $row['ui_nickname']; $ui_nin = $row['ui_nin']; $ui_birth = $row['ui_birth']; } }
html code:
<form action="submit_values.php" method="post"> <!-- code previous fields --> <label class='small-3 columns label_inf_clients'>day of birth*:</label> <div class="small-6 columns select_tag_bottom_margin"> <select id="select_day" name="day" > <?php //the next option should store day $birth_date echo'<option class="option_an" value='.$day.'>'.$day.'</option>'; ?> <?php ($i = 1; $i <= 31; $i++) { echo'<option class="option_an" value=' . $i . ">" . $i . '<option>'; } ?> </select> <select class="select_month" name="month"> <?php //the next option should store month $birth_date echo'<option class="option_an" value='.$month.'>'.$month.'</option>'; ?> <option value="01">jan</option> ............................. <option value="11">nov</option> <option value="12">dec</option> </select> <select class="select_year" name="an"> <?php //the next option should store year $birth_date echo'<option class="option_an" value='.$year.'>'.$year.'</option>'; ($i = 2013; $i >= 1940; $i--) { echo'<option class="option_an" value=' . $i . ">" . $i . '<option>'; } ?> </select> </form>
so let's recap: database select birth date, stored in $ui_birth, want split date in 3 dropdown lists, in next picture: https://docs.google.com/file/d/0b44t4qmqqghay3jkdfznogdltw8/edit?usp=sharing
you can extract components of date php's date functions, so:
$ui_birth = $row['ui_birth']; $birth_date = strtotime($ui_birth); $day = date('d', $birth_date); $month = date('m', $birth_date); $year = date('y', $birth_date);
Comments
Post a Comment