简体   繁体   中英

Output MySQL rows while webpage has been loaded

My desired outcome: Load a webpage completely, but successively output MySQL query row by row when finished.

Explanation: I'd like to have a webpage showing the information it shall show, but at the same time I want it to row by row show how it has processed a MySQL query.

Imagine you submit a task a script will send an e-mail to a bunch of subscribers. When you have submitted that task/script on your webpage you want to come to a new webpage with some information and on that page you have a table that is adding rows in a "live" kind of matter. Adding a row when it has been processed.

The columns could be FIRSTNAME, LASTNAME, E-MAIL, PROCESSED.

The table should be displayed, one row at a time you will get the subscribers and the text OK in the processed column when that has been processed by the script (MySQL query).

No sure I am clear enough in my explanation, do not hesitate to tell me so.

Could it be achievable with php ob_start ?

You can the idea is use of PHP function ob_start(), you can print in batch of 50, 100, or row by row.

    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    ini_set('memory_limit', '512M');
    set_time_limit(0);
    ob_start(); //Object buffer
    //call a recursive function for batch processing
    processTask($pageNo=1);

     function processTask($pageNo=1){
            //perform task with page no 1, like using limit query , 
            //then call function the processTask with next page no if returned
            //row is not equal to zero

            //Must - calling below will out put on browser screen what is in echo statement 
            ob_flush();
            flush();
    }

I would use Javascript (ajax) to repeatedly pull the latest rows as that would cause any HTTP connections to be short-lived and self-contained (as I think they are supposed to be).

This is guesswork, but I think you will be better of in the long run with ajax.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM