 |
การทำ Progress Bar ขณะที่คิวรี่ mysql ครับ ใครมีตัวอย่างให้ดูบ้าง ขอบคุณครับ |
|
 |
|
|
 |
 |
|
ก็เอา update progress ไว้ใน while loop จิ
พอดียังไม่ว่าง จะเอาโค้ดรอวันเสาร์
|
 |
 |
 |
 |
Date :
2014-11-05 11:18:40 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
PHP ผมไม่เคยทำครับ มันเป็นส่วนที่ทำ กับ Server
มันวน loop อยู่บน server
จะทำได้ ก็โดยการ log ลงไฟล์ แล้ว ทำ ajax มาอ่าน จาก log หรือ อ่านจาก record table
Code (PHP)
<?php
if(isset($_POST['run'])){
switch($_POST['run']){
case 'query':
$max=60;
/////////////////////////////////////////////////////////
file_put_contents('filerec.txt', '0' );
file_put_contents('filemax.txt', $max );
sleep(1);
///////////////////////////////////////////////////////
for($i=0; $i<$max; $i++){
// $mysql->query()
file_put_contents('filerec.txt', $i);
sleep(1);
}
file_put_contents('filerec.txt', 'End');
exit;
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script language="javascript" src="jquery-2.1.1.min.js" ></script>
<script language="javascript">
var _max = 9999;
$(document).ready(function(e) {
$('button').click(function(e) {
$('#color').show();
$.ajax({ type:'POST', data: { run: 'query' }});
setTimeout( get_max, 1000);
});
});
function get_max(){
$.ajax({ url: 'filemax.txt' }).done(function(msg){
_max = parseInt(msg);
setTimeout( get_record, 1000 );
});
}
function get_record(){
$.ajax({ url: 'filerec.txt' }).done(function(msg){
if(msg!='End'){
var w = parseInt(msg)*100 / _max;
$('#color').css('width', w +'%');
setTimeout( get_record, 1000 );
}
});
}
</script>
</head>
<body>
<button>Start Query</button>
<div style="width:200; height: 10px" ><div id="color" style="width: 1%; height: 10px; background-color:#666; display: none" /></div>
</body>
</html>
|
 |
 |
 |
 |
Date :
2014-11-05 14:00:41 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|