Speeding up MySQL query



Hi,

I am reusing the results of a MySQL query on a PHP page. The code works
fine but it is taking about 4 to 5 seconds to load the page so I am
wondering if there is a way to make the code more efficient and the
page load more quickly.

At the top of the page I am running the query with the following code.
$id loads through a session variable:

<?

ini_set('max_execution_time', 86400);
$link = mysql_connect($host, $uid, $pwd);
mysql_select_db('Database');
$query = "SELECT DISTINCT `Table`.`Field` FROM `Table` WHERE
`Table`.`ID` = $id ORDER BY Table`.`Field`";
$result = mysql_query($query) or die (mysql_error());

?>

When I want to access the query data I run the following code.

<?php

$i=0;
mysql_data_seek($result,0);
while ($array= mysql_fetch_array($result)) {
?>

HTML
<?php echo $array[Field] ?>">
HTML

<?php
$i++;
}
?>

This code is repeated about four times on the page.

I'd appreciate any suggestions as to how to speed this up.

Regards

Emmett

.



Relevant Pages

  • Re: Lost formatting in browser view source
    ... At the same time your html pages without php-code are processed by php. ... If you are concerned about users links and bookmarks to break, you have the nice option in apache to rewrite rules, if they try to load a "missing" html page, redirect them to a php file with the same name. ... run your editor, load 100 pages, use find/replace to change the address ...
    (alt.php)
  • Re: [PHP] Re: can a session be used in a query?
    ... I've noticed that I somtimes have to get the page to load ... What I normally do is upload a blank php page with the same name as the one ... This one pulls all data regardless of user level: ... the query UserName = $UserName I get an undefined variable error... ...
    (php.general)
  • Re: Firefox destroying layout upon page load / reload fixes it
    ... I have a php based site. ... The problem is when I click on a link or load various pages on the ... HTML is just a standard table. ... No CSS in this situation. ...
    (comp.lang.php)
  • Re: How to pull existing Title tag into the body of the document as text only
    ... >the body of the html page. ... We started coding this with php, ... >and really bogging down the system and the pages load very slowly. ... >To fix this we decided to just use javascript, ...
    (alt.php)
  • Re: php table
    ... On Feb 3, 8:42 pm, Jerry Stuckle wrote: ... > group but some d-bag told me that it was an html question. ... > this is a php question. ... You need a query, you need to send the query to a database and fetch the results, you need to use the result to generate html. ...
    (comp.lang.php)