Re: speeing up query and display...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You've got three queries, two of which are in while loops.  If you're calling up
3000 records, you may have as many as 3000 DB queries, possibly more.  That's
why things take forever.

Restructure your code, placing the queries outside the loops.  Then use
mysql_fetch_array() and loop through the result sets.  While you're at it, stop
closing out of PHP to write one character.  Simply enclose your echo/print text
with single quotes so that PHP knows not to evaluate it.

To start you off, I've done most of the later work.  I've also taken the liberty
of neatly formatting your code so that it's easier to follow.  Good luck with
the rest.

<?php
$manufQuery = db_query("SELECT manufacturer FROM kcs_threads");
while ($manufResults = db_fetch($manufQuery))
    echo '<option value="">'.$manufResults[manufacturer].'</option>';

$threadQuery = db_query("SELECT id,colour,colourID FROM kcs_threads LIMIT 10");

while ($threadResults = db_fetch($threadQuery)) {
    $threadselectQuery = db_query("SELECT * FROM kcs_patternthreads WHERE
pattern_index='$id'");

    while ($threadselectResult = db_fetch($threadselectQuery)) {
        echo '<option value="'.$threadResults[id].'"';
        if ($threadselectResult[thread_index] == $threadResults[id])
            echo 'checked>'.$threadResults[colour].'</option>';
    }
}
?>

Edward Dudlik
Becoming Digital
www.becomingdigital.com


Did I help you?  Want to show your thanks?
www.amazon.com/o/registry/EGDXEBBWTYUU



----- Original Message -----
From: "Aaron Wolski" <aaronjw@martekbiz.com>
To: <php-db@lists.php.net>
Sent: Saturday, 19 July, 2003 13:29
Subject:  speeing up query and display...


Hi Guys,

I have the following query which unfortunately has to grab all records
in a table (well over 3000) to display in a multiple select box.

Code:

<?php

                $manufQuery = db_query("SELECT manufacturer FROM
kcs_threads");
                while ($manufResults = db_fetch($manufQuery)) {

?>
                <option value=""><?php echo $manufResults[manufacturer];
?></option>

<?php

$threadQuery = db_query("SELECT id,colour,colourID FROM kcs_threads
LIMIT 10");
while ($threadResults = db_fetch($threadQuery)) {

                $threadselectQuery = db_query("SELECT * FROM
kcs_patternthreads WHERE pattern_index='$id'");
                while ($threadselectResult =
db_fetch($threadselectQuery)) {

?>
                <option value="<?php echo $threadResults[id]; ?>" <?php
if ($threadselectResult[thread_index] == $threadResults[id]) echo
"checked"; ?>><?php echo $threadResults[colour]; ?></option>

<?php

                                                }
                                }
                }

?>

Can ANYONE see a way to speed up the query and displaying of the
results? Take a while on High Speed and WAAAAY to long on Dialup.

Thanks a lot

Aaron




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux