0
<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>

The query is very fast. But the ComboBox is filling up too slowly. 200 shots are filling in 10 seconds. However, the query does not last for 1 second. Can you help me please ?

miken32
  • 39,644
  • 15
  • 91
  • 133
  • Why don't you get the options before creating the combobx? And then fill it – Lucarnosky Sep 22 '17 at 09:31
  • It's hard to say what can be the issue in such a trivial case. Did you measure the execution time using this technique: https://stackoverflow.com/questions/6245971/accurate-way-to-measure-execution-times-of-php-scripts – user4035 Sep 22 '17 at 10:06
  • @Lucarnosky I do not understand what you suggest ? – soner cafer Sep 25 '17 at 15:36

1 Answers1

0

This may just end up moving the delay to the beginning of page load instead of during page load, but mixing your PHP and HTML like this is just messy and unmanageable. Ideally you should be totally separating the two (look up MVC for details) but if you have it in a single file, do it like this:

<?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 -->

Note the use of alternative syntax and short echo tags to reduce PHP syntax within HTML, and htmlspecialchars() to provide safe output.

I'd also recommend moving to a more modern database API like PDO which may give better performance. Since you haven't provided your full code (what is $baglanti?) I can't suggest much beyond that.

miken32
  • 39,644
  • 15
  • 91
  • 133