我必须将插入db行的记录拉入html选择框,这样它们就必须显示在选项标签中。
if (isset($_POST['add'])) {
require ('connect.php');
$sql = $db->prepare("INSERT INTO lavoro (provincia,sede,settimana,giorno,ora) VALUES (:provincia,:sede,:settimana,:giorno,:ora)") or die ('Ciao1');
$sql->execute(array(':provincia'=>$_POST['provincia'],':sede'=>$_POST['sede'],':settimana'=>$_POST['settimana'],':giorno'=>$_POST['giorno'],':ora'=>$_POST['ora'])) or die('Non aggiorna nulla');
echo '<select>';
echo '<option></option>';
echo '</select>';
}
代码OP发布在下面的评论中
if (isset($_POST['search'])) {
require ('connect.php');
$sql = $db->prepare("SELECT sede FROM lavoro") or die ('Ciao1');
$sql->execute();
$result = $sql->fetchAll();
print_r($result);
echo '<select>';
echo '<option></option>';
echo '</select>';
}
答案 0 :(得分:0)
在评论中使用您的代码,尝试类似
的内容if (isset($_POST['search'])) {
require ('connect.php');
$sql = $db->prepare("SELECT sede FROM lavoro") or die ('Ciao1');
$sql->execute();
$result = $sql->fetchAll();
echo '<select name="sede">';
foreach($result as $value){
echo "<option value='{$value['sede']}'>{$value['sede']}</option>";
}
echo '</select>';
}