Re: Speeding up MySQL query
- From: Kris Peeters <fname.lname@xxxxxxxxx>
- Date: Fri, 09 Sep 2005 08:15:40 +0200
EmmettPower@xxxxxxxxx wrote:
> 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
Just guessing: are the fields Table.Field and Table.ID indexed in MySQL ??
--
Kris.
.
- References:
- Speeding up MySQL query
- From: EmmettPower
- Speeding up MySQL query
- Prev by Date: Getting info from an HTML file
- Next by Date: localhost?
- Previous by thread: Re: Speeding up MySQL query
- Next by thread: Getting info from an HTML file
- Index(es):
Relevant Pages
|