Page 1 of 1

PHP complex sql queries within FOR LOOPs

Posted: Fri Aug 14, 2009 8:31 pm
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

Re: PHP complex sql queries within FOR LOOPs

Posted: Fri Aug 14, 2009 8:40 pm
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.

Re: PHP complex sql queries within FOR LOOPs

Posted: Sat Aug 15, 2009 4:24 am
by webmonkey88
ye that looks utterly stupid, you have horrible column names table names ect i would suggest going back to tutorials