You are here: Re: Is foreach the fastest way to do this? « PHP Programming Language « IT news, forums, messages
Re: Is foreach the fastest way to do this?

Posted by david on 08/08/06 06:02

On 2006-08-06 09:46:02 -0700, s a n j a y <sanjay.debian@gmail.com> said:

> david wrote:
>> I need 5 queries from the database, which I display in a php foreach
>> loop the following way.
>>
>> $query1 = $DB->query("SELECT ... DESC LIMIT 20");
>> $query2 = $DB->query("SELECT ... DESC LIMIT 20");
>> $query3 = $DB->query("SELECT ... DESC LIMIT 30");
>> $query4 = $DB->query("SELECT ... DESC LIMIT 9");
>> $query5 = $DB->query("SELECT ... DESC LIMIT 9");
>>
>> foreach ($query1->result as $row) {
>> echo '<a href="httplink/'.$row['topic_id'].'/"
>> title="'.htmlspecialchars(trim($row['screen_name'])).':
>> '.htmlspecialchars(trim($row['title'])).'">&raquo;
>> '.substr($row['title'], 0, 20)." ...</a><br />
>> ";}
>> foreach ($query2->result as $row) {
>> echo '<a href="httplink/'.$row['topic_id'].'/"
>> title="'.htmlspecialchars(trim($row['screen_name'])).':
>> '.htmlspecialchars(trim($row['title'])).'">&raquo;
>> '.substr($row['title'], 0, 20)." ...</a><br />
>> ";}
>>
>> and so on....
>>
>> Looking only at performance is there a quicker way to do this? Could I
>> use a different loop (other than foreach) to get better performance?
>>
>> I found the following page, but I am not sure which one would help me
>> and how to change the code around to make it work. Any ideas would
>> help. Thank you!
>> http://www.php.lt/benchmark/phpbench.php
>>
>> david
>>
>
> Why do you want to split hairs? How does 8 ms different than 12 ms in
> practical sense?

Well, when you have hundreds of requests coming in within a short
period of time, those ms add up. This is why I am trying to optimize
this function. Any ideas on how to make this the quickest?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация