<select class="input-xlarge" name="safihacinsi">
<option value=""></option>
<?php
$sorgu="SELECT Stok_Karti.StokID,Stok_Karti.WebStokKodu + ' ' + Stok_Karti.WebStokIsmi AS StokAdi FROM Stok_Karti INNER JOIN Stok_Karti_Cins ON Stok_Karti.StokID = Stok_Karti_Cins.StokID WHERE Stok_Karti.Durum=0 and Stok_Karti_Cins.StokCinsID = 12 order By Stok_Karti.StokKodu +' - '+Stok_Karti.StokIsmi";
$sonuc=odbc_exec($baglanti,$sorgu);
while($satir = odbc_fetch_array($sonuc))
{
?>
<option value="<?php echo $satir['StokID']; ?>"><?php echo $satir['StokAdi']; ?></option>
<?php
}
?>
</select>
查询非常快。但是ComboBox的填充速度太慢了。在10秒钟内完成200次射击。但是,查询不会持续1秒钟。你能帮帮我吗?
答案 0 :(得分:0)
这可能最终会将延迟移到页面加载的开头,而不是在页面加载期间,但是像这样混合你的PHP和HTML只是混乱和无法管理。理想情况下,您应该将两者完全分开(查找MVC以获取详细信息),但如果您将其放在单个文件中,请执行以下操作:
<?php
// this is the very first thing in your file
// do your PHP separately
$sorgu = "SELECT Stok_Karti.StokID, Stok_Karti.WebStokKodu + ' ' + Stok_Karti.WebStokIsmi AS StokAdi
FROM Stok_Karti
INNER JOIN Stok_Karti_Cins ON Stok_Karti.StokID = Stok_Karti_Cins.StokID
WHERE Stok_Karti.Durum=0
AND Stok_Karti_Cins.StokCinsID = 12
ORDER BY Stok_Karti.StokKodu +' - '+Stok_Karti.StokIsmi";
$sonuc = odbc_exec($baglanti, $sorgu);
while ($satir = odbc_fetch_array($sonuc)) {
$options[] = $satir;
}
?>
<!-- here is the HTML... -->
<select class="input-xlarge" name="safihacinsi">
<option value=""></option>
<?php foreach ($options as $option):?>
<option value="<?=htmlspecialchars($option["StokID"])?>">
<?=htmlspecialchars($option["StokAdi"])?>
</option>
<?php endforeach;?>
</select>
<!-- the rest of the HTML -->
请注意使用alternative syntax和short echo tags来减少HTML中的PHP语法,并使用htmlspecialchars()
来提供安全输出。
我还建议转向更现代的数据库API,如PDO,这可能会提供更好的性能。既然你还没有提供完整的代码(什么是$baglanti
?),除此之外我不能提出太多建议。