我正在从 MySQL 加载 30000 个值并将其加载为下拉选择。加载所有值后,它可以正常工作,但填充下拉列表需要很长时间。我做错了还是应该使用自动完成等其他方式?
谢谢
HTML 代码:
<div class="control">
<label for="options" class="short">Fornecedor</label>
<select id="fornecedor" name="fnd[]" multiple="multiple" class="short">
<?php
$rows = getFornecedores($db);
foreach($rows as $row): ?>
<option value="<?php echo html_escape($row['idfornecedor']) ?>"><?php echo html_escape($row['nome']) ?></option>
<?php endforeach; ?>
</select>
</div>
PHP函数:
function getFornecedores($db){
$query = "
SELECT
idfornecedor, nome
FROM
fornecedor
ORDER BY
nome
";
try
{
$stmt = $db->prepare($query);
$stmt->execute();
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
$rows = $stmt->fetchAll();
return $rows;
}