How to Use PHP to process database data to return data to the client and display the current status, php current status

Source: Internet
Author: User

How to Use PHP to process database data to return data to the client and display the current status, php current status

Php processes a large amount of data. Each time a piece of data is processed, the method returned to the client to display the current status.

Similar to dedecms for generating static pages

Idea:

1. The client sends a request
2. The server receives the request and starts to count the data volume to be processed.
3. Sort the data to be processed according to certain rules and send them to the server processing end.
4. The server processing end processes the first data and sends the processing result to the client after some processing.
5. When the client receives the result, it automatically displays the result and sends it to the server.
6. The server receives the processing result and forwards it to the server processing end.
7. The processing end continues to process the results...
8. loop through steps 4-7 until the processing is completed

Experiment process:

1. create databases and tables

create databases handle;create table user(id int unsigned not null auto_increment primary key,name varchar(8),sex tinyint(1) default '1',score int not null,state tinyint(1)); 

2. Add data to the table (not for example)

3.create the index.html client, a. php server 1, B. php server 2

Index.html:

<! DOCTYPE html> 

A. php:

<? Phprequire ('. /dbconfig. php '); $ link = mysql_connect (HOST, USER, PASS) or die ('database link failed'); mysql_select_db (DBNAME ); /* query data $ SQL = "select * from user"; $ result = mysql_query ($ SQL); $ row = mysql_fetch_assoc ($ result); var_dump ($ row ); * // * cyclically insert for ($ I = 3; $ I <= 100; $ I ++) {$ SQL = "insert into user (name, score, state) values ('z ". $ I. "',". $ I. ", 1)"; mysql_query ($ SQL);} * // * Total Number of data to be processed * // isset ($ _ GET ['state'])? $ _ GET ['state']: 0; if (isset ($ _ GET ['state']) {$ SQL = "select count (*) from user "; $ result = mysql_query ($ SQL); $ all = mysql_result ($ result, 0); $ now = 0; header ("Location: B. php? All = {$ all} & now = 0 ");} else {header (" Location: B. php? All = {$ _ GET ['all']} & now = {$ _ GET ['now ']} ");}/* return the data currently processed */

B. php:

<? Phprequire ('. /dbconfig. php '); $ link = mysql_connect (HOST, USER, PASS) or die ('database link failed'); mysql_select_db (DBNAME ); /* return the currently processed data * // $ id = $ _ GET ['id']; // obtain the id $ now =$ _ GET ['now ']; // number of processed items $ all =$ _ GET ['all']; // total number of tasks to be processed $ SQL = "select score from user limit {$ now}, 1"; $ result = mysql_query ($ SQL ); $ value = mysql_result ($ result, 0); $ now ++; $ arr = array ('right' => $ now, 'all' => $ all, 'value' => $ value); // print_r ($ arr); echo json_encode ($ arr );

Dbconfig. php:

<?phpdefine('HOST','127.0.0.1');define('USER', 'root');define('PASS','root');define('DBNAME','handle'); 

The above section describes how to use PHP to process database data and return the data to the client and display the current status!

Articles you may be interested in:
  • Two Methods for MySQL client to directly connect to the database without entering the user name and password
  • Dblink syntax for oracle database creation on the client
  • Notes for beginners of DB2: new instance, database path does not exist, client connection.
  • Orcale database client PL/SQL Chinese garbled Problem Solution
  • Python web programming learning notes (9): Database client DB-API
  • PostgreSQL database server listener settings and Client Connection Methods tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.