-3

我必须将插入到 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>'; 
}
4

1 回答 1

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>'; 
}
于 2013-06-11T15:43:58.187 回答