使用数组中的值填充HTML下拉框

时间:2017-07-18 02:17:59

标签: php html forms

我一直在研究这个问题并且我仍然遇到问题。

以下是代码:



<body>

<?php
//To start, there is a form with a dropbox and a button, which will have the various functions that can happe
?>

<form action="search_start.php" method="post">
    Function <select name="Functions">
    <?php
    $fns_to_choose = array(
        "Option 1" =>"Get A Monthly Report",
        "Option 2" => "Track One Ship Over Time",
        "Option 3" => "Track Multiple Ships Over Time",
        "Option 4" => "Get Ships Over Time For One$
    ?>
    <select> 
        <?php
        foreach ($fns_to_choose as $key => $value)  {
            echo '<option value="' . $key . '">' . $value . '</option>'; 
        }
        ?>
    </select>
</form>
&#13;
&#13;
&#13;

所发生的情况是,不是使用数组的元素来填充下拉列表,而是仅仅回显了元素#39;在一个空的下拉列表下面,看起来像这样:

从我在本网站上的其他答案中看到的情况来看,选项应该填写表格,而不是仅仅在其下面。

绝对欢迎任何建议。

我觉得这就像是最基本的东西,而我却无法弄清楚。

3 个答案:

答案 0 :(得分:0)

有一些语法错误,修复如下,你可以再试一次吗?

#include "mainwindow.h"
#include <QApplication>
#include <QWindow>
#include <QDesktopWidget>
#include <QDebug>

int main(int argc, char *argv[])
{
    int ScreenIDWhereToShowWindow = 1;
    QApplication a(argc, argv);
    MainWindow w;


    QDesktopWidget *desk = new QDesktopWidget();

    w.setGeometry(desk->screenGeometry(ScreenIDWhereToShowWindow));
    w.showFullScreen();
    QApplication::setOverrideCursor(Qt::BlankCursor);

    qDebug() << desk->screenGeometry(0);
    qDebug() << desk->screenGeometry(1);
    qDebug() << desk->screenGeometry(2);
    return a.exec();
}

答案 1 :(得分:0)

您有2 <select>个标签导致嵌套,这是不允许的。删除其中一个,这应该可以解决问题。

答案 2 :(得分:0)

所以,

在我发布这个之后我找到了答案。问题是我尝试有效地创建两个下拉列表。所以我删除了第一个,现在它工作得很好。

我把它留在这里因为......好吧......坦率地说,我的愚蠢可能会帮助别人。

相关问题