我需要从三个下拉列表中的数据库中检索日期。Mysql & PHP 代码:
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else {
$sql = "SELECT ui.`sex` AS ui_sex ,
ui.`last_name` AS ui_lname,
ui.`first_name` AS ui_fname,
ui.`nickname` AS ui_nickname,
ui.`nin` AS ui_nin,
ui.`birth_date` AS ui_birth,
WHERE 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 代码:
<form action="submit_values.php" method="POST">
<!-- Code for 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 the day from $birth_date
echo'<option class="option_an" value='.$day.'>'.$day.'</option>';
?>
<?php
for ($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 the month from $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 the year from $birth_date
echo'<option class="option_an" value='.$year.'>'.$year.'</option>';
for ($i = 2013; $i >= 1940; $i--) {
echo'<option class="option_an" value=' . $i . ">" . $i . '<option>';
}
?>
</select>
</form>
让我们回顾一下:我从数据库中选择存储在 $ui_birth 中的出生日期,我想将此日期拆分为 3 个下拉列表,如下图所示:https ://docs.google.com/file/d/0B44T4qmqQGHAY3JkdFZNOGdLTW8 /edit?usp=共享