How database data is processed using PHP to return data to the client and display the current state _php instance

Source: Internet
Author: User
Tags create index php server

PHP processes a large amount of data, each processing a data return client to display the current state of the method.

Similar to dedecms generating static pages

Idea:

1. Client sends request
2. Server-side accept request, start to count the amount of data required to process
3. Arrange the processing data according to certain rules, send to server processing end
4. The server processing side processed the first data, the processing results after a certain processing sent to the client
5. The client receives the result, automatically displays the processing results and sends it to the server
6. The server receives processing results and forwards it to the server processing end
7. Processing end to continue processing results ...
8. Cycle 4-7 steps until processing is complete

Experimental process:

1. Creating databases and Tables

create databases handle;
CREATE TABLE user (
ID int unsigned NOT NULL auto_increment primary key,
name varchar (8),
sex tinyint (1) defaul T ' 1 ',
score int not NULL, state
tinyint (1)

2. Add data to the table (no example)

3. Create index.html client, a.php server 1,b.php service End 2

Index.html:

<! DOCTYPE html>
 
 

a.php:

<?php
require ('./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);
* *
*
loop Insert for
($i =3 $i <=100; $i + +) {
$sql = INSERT INTO user (Name,score,state) VALUES (' Z ". $i. "',". $i. ", 1)";
mysql_query ($sql);
* * *
Query The 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 '}");
}

b.php:

<?php
require ('./dbconfig.php ');
$link =mysql_connect (Host,user,pass) or Die (' Database link failed ');
mysql_select_db (dbname);
/* Returns the currently processed data
///$id =$_get[' id '];//gets the ID to be processed
$now =$_get[' Now '];//has been processed
$all =$_get[' all '];// The total number of items to be processed
$sql = "Select score from user limit {$now},1";
$result =mysql_query ($sql);
$value =mysql_result ($result, 0);
$now + +;
$arr =array (
' Now ' => $now,
' All ' => $all,
' value ' => $value
);
Print_r ($arr);

dbconfig.php:

<?php
define (' HOST ', ' 127.0.0.1 ');
Define (' USER ', ' root ');
Define (' Pass ', ' root ');

The above is a small set for everyone to share the use of PHP processing database data to return the data to the client and display the current state, I hope to help you!

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.