Re: What's faster? MySQL Queries or PHP Loops?
| From: | Robb Kerr | Date: | Wed, 08 Sep 2004 18:31:07 +0000 |
| Subject: | Re: What's faster? MySQL Queries or PHP Loops? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-196148@lists.php.net to get a copy of this message | ||
On Wed, 8 Sep 2004 10:30:59 -0500, Jim Grill wrote:
>> Here's the question...
>>
>> I can either A) in the header or my page, generate a recordset of all of
>> the records in the related table and then loop through the recordset
>> creating an array of the fields I need and then later pull from it in the
>> repeat region... or B) take the six lines of code Dreamweaver generates to
>> create a recordset and move them into the repeat region itself. In other
>> words, I can create a recordset of all of the records in the related
> table,
>> loop through it generating a PHP array and pull from this array later OR I
>> can query the database every time through the loop while creating the
>> repeat region.
>>
>> Robb Kerr
>> Digital IGUANA
>> Helping Digital Artists Achieve their Dreams
>> ----------------------------------------------------
>> http://www.digitaliguana.com
>> http://www.cancerreallysucks.org
>>
> Robb,
>
> How about choice "C"? :-)
>
> Query once if you can. Running multiple queries in a loop is always going to
> be slower. Now, I'm not totally sure I understand the problem. It sounds
> like you have one table to query and then you query a second table??? If
> that's true then what about a join to get everything you need from both
> tables at once? The idea here is that you get one result from MySQL and then
> loop through your result and display your content.
>
> Hope I'm not too far off.
>
> Jim Grill
That brings up another question which I know actually belongs over on the
MySQL board, but since the question arose here I thought I'd post here. I
understood that MyISAM tables could not be relational. Do you mean that I
can create JOINs between MyISAM tables? Maybe I need to do some more
research into table types?
--
Robb Kerr
Digital IGUANA
Helping Digital Artists Achieve their Dreams
----------------------------------------------------
http://www.digitaliguana.com
http://www.cancerreallysucks.org