最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用PHP處理數(shù)據(jù)庫數(shù)據(jù)如何將數(shù)據(jù)返回客戶端并顯示當前狀態(tài)

 更新時間:2016年02月16日 09:12:19   作者:ZJH_BLOGS  
這篇文章給大家介紹使用php處理大量數(shù)據(jù),每處理一個數(shù)據(jù)返回客戶端顯示當前狀態(tài)的方法,對PHP處理數(shù)據(jù)庫數(shù)據(jù)返回客戶端并顯示當前狀態(tài)的相關(guān)知識感興趣的朋友一起學習吧

php處理大量數(shù)據(jù),每處理一個數(shù)據(jù)返回客戶端顯示當前狀態(tài)的方法。

類似于dedecms生成靜態(tài)頁

想法:

1.客戶端發(fā)送請求
2.服務(wù)器端接受請求,開始統(tǒng)計所需處理的數(shù)據(jù)量
3.將所需處理數(shù)據(jù)按一定規(guī)則排列,發(fā)送到服務(wù)器處理端
4.服務(wù)器處理端處理了第一個數(shù)據(jù),將處理結(jié)果經(jīng)過一定處理后發(fā)送給客戶端
5.客戶端接收到結(jié)果,自動將處理結(jié)果顯示并發(fā)送到服務(wù)器
6.服務(wù)器接收到處理結(jié)果 將它轉(zhuǎn)發(fā)到服務(wù)器處理端
7.處理端繼續(xù)處理結(jié)果...
8.循環(huán)4-7步驟,直到處理完畢

實驗過程:

1.創(chuàng)建數(shù)據(jù)庫和表

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.向表中添加數(shù)據(jù)(不示例)

3.創(chuàng)建index.html客戶端,a.php服務(wù)端1,b.php服務(wù)端2

Index.html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>客戶端</title>
</head>
<body>
<button onclick="send('a.php?state=0')">開始請求</button>
<div style="position: fixed;width: 500px;height: 300px;top: 100px;background: gray">
<span style="color: white;font-size: 20px;"></span>
</div>
<script type="text/javascript" src="./jquery-1.10.2.min.js"></script>
<script type="text/javascript">
//創(chuàng)建一個模態(tài)框
function display(value){
$('span').html(value);
}
//ajax
function send(dizhi){
$.ajax({
type: "get",
url: dizhi,
success: function(msg){
var arr=JSON.parse(msg);
console.log(arr);
//alert(arr.value);
var tishi="已經(jīng)處理 "+arr.now +"個,共"+arr.all+"個";
display(tishi);
if(arr.now!=arr.all){
send("a.php?now="+arr.now+"&all="+arr.all);
}else{
alert("完成!");
}
}
});
}
</script>
</body>
</html> 

a.php:

<?php
require('./dbconfig.php');
$link=mysql_connect(HOST,USER,PASS) or die('數(shù)據(jù)庫鏈接失敗');
mysql_select_db(DBNAME);
/*
查詢數(shù)據(jù)
$sql="select * from user";
$result=mysql_query($sql);
$row=mysql_fetch_assoc($result);
var_dump($row);
*/
/*
循環(huán)插入
for($i=3;$i<=100;$i++){
$sql= "insert into user(name,score,state) values('z".$i."',".$i.",1)";
mysql_query($sql);
}
*/
/*查詢需要處理的數(shù)據(jù)總數(shù)*/
//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']}");
}
/*返回當前處理的數(shù)據(jù)*/ 

b.php:

<?php
require('./dbconfig.php');
$link=mysql_connect(HOST,USER,PASS) or die('數(shù)據(jù)庫鏈接失敗');
mysql_select_db(DBNAME);
/*返回當前處理的數(shù)據(jù)*/
//$id=$_GET['id'];//獲取將要處理的id
$now=$_GET['now'];//已經(jīng)處理的個數(shù)
$all=$_GET['all'];//總共要處理的個數(shù)
$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);
echo json_encode($arr); 

dbconfig.php:

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

以上所述是小編給大家分享的使用PHP處理數(shù)據(jù)庫數(shù)據(jù)如何將數(shù)據(jù)返回客戶端并顯示當前狀態(tài),希望對大家有所幫助!

相關(guān)文章

最新評論

峨眉山市| 丘北县| 抚顺县| 滁州市| 澄迈县| 兴隆县| 潮州市| 会东县| 哈密市| 吉首市| 江门市| 巧家县| 宁乡县| 定安县| 广州市| 桃江县| 巴中市| 方城县| 祁门县| 高碑店市| 新沂市| 阿鲁科尔沁旗| 门源| 宣汉县| 广东省| 车致| 苗栗市| 信丰县| 阿克苏市| 托克托县| 西盟| 周宁县| 邛崃市| 河北区| 辉县市| 伊宁市| 隆子县| 云林县| 五台县| 绥芬河市| 景洪市|