Multiple queries in a PHP page

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
markniazi
Forum Newbie
Posts: 3
Joined: Mon Nov 14, 2011 9:46 am

Multiple queries in a PHP page

Post by markniazi »

I have 20 mysql queries in a PHP page, browser displays the output when all queries are processed, it takes about 1 minute.

Is there any way that results are shown one by one, I mean, first query is processed and results are displayed, then 2nd query is processed and results are displayed on the same page and so on.

Kindly suggest a solution.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Multiple queries in a PHP page

Post by Celauran »

You could have query, then display results, then next query, then display those results, etc. I'd be far more concerned about why you have 20 queries and why they're taking so long.
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: Multiple queries in a PHP page

Post by maxx99 »

Something like this could do the trick. But its not a good solution :(

Code: Select all

for($i=0;$i<10;$i++){
    echo "x";//query result
    sleep(1);
     myflush();
}
function myflush (){
     echo(str_repeat(' ',256));
     // check that buffer is actually set before flushing
     if (ob_get_length()){            
         @ob_flush();
         @flush();
         @ob_end_flush();
     }    
     @ob_start();
 }
You can always do SYNC AJAX requests client side :)
markniazi
Forum Newbie
Posts: 3
Joined: Mon Nov 14, 2011 9:46 am

Re: Multiple queries in a PHP page

Post by markniazi »

Well Celarun, its an assignment, in which I have to manage 20 to 30 queries inside a PHP page
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Multiple queries in a PHP page

Post by califdon »

I have the same concern as Celauran. You say that it is an 'assignment'? Like a school assignment? If that is the case, you would need to tell us exactly what the assignment asked you (not us) to do, word for word. And we would need to know what specific programming areas your lectures and reading have covered. As a retired college instructor, I know that just asking someone to give you a solution won't work. The instructor is trying to get a specific answer based on what your previous and current reading and lectures are attempting to teach you. Something that I might suggest to you is likely to not be the answer the instructor is looking for at this point in your studies.
Post Reply