PHP complex sql queries within FOR LOOPs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tresa123
Forum Newbie
Posts: 1
Joined: Fri Aug 14, 2009 8:23 pm

PHP complex sql queries within FOR LOOPs

Post by tresa123 »

Hi,

I have been struggling with improving the web loading time for a php page and there is not improvement in it. I do know that the php page slows down just because of the complex sql query being run in teh for loop for 100 times.

Does anyone know how to improve it so that the web loading time for the php page would improve?
Something similar would be

Code: Select all

for(i=0i<ctr;i++)
{
select table1.A,table2.B,C,D,E,F,G,H,I,J from table1,table2 where B='var1' and ((datevar between 'D' and 'E')or (datevar between 'D' and 'E')) and  table1.A like'somevalue%' and table2.B='somevalue' and E like 'var23' 
 
print *************;
 
}
 
I am printing the output of this query in a table.

Thanks,
Tresa
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: PHP complex sql queries within FOR LOOPs

Post by Eran »

very simple solution - do not run a similar query 100 times! run one query to fetch all the data and then iterate over the results.
webmonkey88
Forum Newbie
Posts: 20
Joined: Fri Aug 14, 2009 4:30 am

Re: PHP complex sql queries within FOR LOOPs

Post by webmonkey88 »

ye that looks utterly stupid, you have horrible column names table names ect i would suggest going back to tutorials
Post Reply