填充从页面加载的查询中选择

时间:2017-05-12 16:57:16

标签: php html arrays joomla

我想执行一个查询,并在页面加载时使用返回的结果集填充Select。因此,当页面完全加载时,Select将有选项。我有这种语法,但从页面加载到选择列表填充大约有10-15秒的延迟。是否有语法问题,或更好的方法来设置它,以便人口完全定时/

    <html>
<?php
    //Connect to the database
    $mysqli = new mysqli("localhost", "root", "", "bible");

    //Return an error if we have a connection issue
    if ($mysqli->connect_error) {
        die('Connect Error (' . $mysqli->connect_errno . ') '
                . $mysqli->connect_error);
        }

    $query = $mysqli->query("select empID as Name from employees");

    while($array[] = $query->fetch_object());

    array_pop($array);
?>
    <h3>Employee List:</h3>
    <select name="the_name">
    <?php foreach($array as $option) : ?>
        <option value="<?php echo $option->Name; ?>"></option>
    </select>
        <?php endforeach; ?>
</html>

修改
这是完整的语法(从我的实际页面),现在每当我尝试加载页面时,我得到500错误?

<form method="POST">
<html>
<tbody>  
Hire Date:<input type="date" name="hiredate" value="<?=$_POST['hiredate']?>">
Term Date:<input type="date" name="termdate" value="<?=$_POST['termdate']?>">
<input type="submit" name="submit" value="Submit">
<select name="InvoiceNum">
<?php 
$option = array();
$option['driver'] = 'mssql'; 
$option['host'] = 'IP ADDRESS'; 
$option['user'] = 'user name'; 
$option['password'] = 'password'; 
$option['database'] = 'database'; 
$option['prefix'] = '';
$db = JDatabase::getInstance( $option );
$sql = $db->getQuery(true);
$sql = mssqli_query($connection, "SELECT InvoiceNum FROM MonthlyInvoices ORDER BY InvoiceNum ASC");
$db->setQuery($sql); 
$sql = $db->loadObjectList();
while ($row = $sql->fetch_assoc()){
    echo "<option value=\"{$row['InvoiceNum']}\">{$row['InvoiceNum']}</option>";
}
?>
</select></tbody></html> </form>

0 个答案:

没有答案