好友
阅读权限30
听众
最后登录1970-1-1
|
本帖最后由 zoenbo 于 2020-12-1 17:21 编辑
折腾了两天,没找出问题在哪,用的layui的JS,内容无法分页,哪位大佬帮我看看问题出在哪了,拜托了~~~
PHP页面[PHP] 纯文本查看 复制代码 <?php
$str= file_get_contents("3.txt");//将文件中的内容读成字符串
$str1=explode("\n",$str);//按换行进行拆分//单引号是转义字符,所以必须使用双引号
$data = [];
$count = count($data);
$page = $_GET['page'];
$limit = $_GET['limit'];
$firstIndex=($page-1)*$limit;
$new = array_slice($data,$firstIndex,$limit);
$data1 = [];
$i = 0;
foreach($str1 as $value){
$val = json_decode($value,true);
$data[] = [
'time'=>$val['time'],
'ip'=>$val['ip'],
'user_agent'=>$val['user_agent'],
'url'=>$val['url'],
'query'=>$val['query'],
];
}
$response_list=[
'code'=>'0',
'msg'=>'',
'count'=>$count,
'data'=>$data
];
//print_r($response_list);
echo json_encode($response_list);
?>
HTML页面
[Asm] 纯文本查看 复制代码 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>统计数据</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/layui-src@2.5.5/src/css/layui.css">
<style>.layui-row{width:1200px;margin:0 auto;}</style>
</head>
<body>
<div class="layui-row">
<div class="layui-col-xs6 layui-col-md12">
<table id="demo" lay-filter="test"></table>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/layui-src@2.5.5/dist/layui.min.js"></script>
<script>
layui.use('table', function(){
var table = layui.table;
//第一个实例
table.render({
elem: '#demo'
,url: 'index2.php' //数据接口
,page: true //开启分页index
,cols: [[ //表头
{field: 'time', title: '时间', width:160, fixed: 'left',sort: true}
,{field: 'ip', title: 'IP', width:120}
,{field: 'user_agent', title: '用户代理', width:400}
,{field: 'url', title: '网址', width:200}
,{field: 'query', title: '参数'}
]]
});
});
</script>
</body>
</html>
3.txt
{"time":"2020-11-27 09:41:01","ip":"193.168.0.1","user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.198 Safari\/537.36 Edg\/86.0.622.69","url":"http:\/\/damn.com\/","query":""}
{"time":"2020-11-27 09:41:43","ip":"192.168.0.1","user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.198 Safari\/537.36 Edg\/86.0.622.69","url":"http:\/\/damn.com\/","query":""}
{"time":"2020-11-27 09:44:16","ip":"195.168.0.1","user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.198 Safari\/537.36 Edg\/86.0.622.69","url":"http:\/\/damn.com\/","query":""}
{"time":"2020-11-27 10:03:01","ip":"192.168.0.1","user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.198 Safari\/537.36 Edg\/86.0.622.69","url":"http:\/\/damn.com\/","query":"null=1"}
{"time":"2020-11-27 10:03:29","ip":"192.168.0.1","user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.198 Safari\/537.36 Edg\/86.0.622.69","url":"http:\/\/damn.com\/","query":""}
{"time":"2020-11-27 09:41:01","ip":"192.168.0.1","user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.198 Safari\/537.36 Edg\/86.0.622.69","url":"http:\/\/damn.com\/","query":""}
{"time":"2020-11-27 09:41:43","ip":"192.168.0.1","user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.198 Safari\/537.36 Edg\/86.0.622.69","url":"http:\/\/damn.com\/","query":""}
{"time":"2020-11-27 09:44:16","ip":"192.168.0.1","user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.198 Safari\/537.36 Edg\/86.0.622.69","url":"http:\/\/damn.com\/","query":""}
{"time":"2020-11-27 10:03:01","ip":"192.168.0.1","user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.198 Safari\/537.36 Edg\/86.0.622.69","url":"http:\/\/damn.com\/","query":"null=1"}
{"time":"2020-11-27 10:03:29","ip":"192.168.0.1","user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.198 Safari\/537.36 Edg\/86.0.622.69","url":"http:\/\/damn.com\/","query":""}
{"time":"2020-11-27 09:41:01","ip":"192.168.0.1","user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.198 Safari\/537.36 Edg\/86.0.622.69","url":"http:\/\/damn.com\/","query":""} |
|