吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1175|回复: 2
收起左侧

[已解决] 哪位PHP大佬帮我看看这个分页问题出哪了~

[复制链接]
zoenbo 发表于 2020-11-30 21:29
本帖最后由 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":""}

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

大手笔 发表于 2020-12-1 03:47
[PHP] 纯文本查看 复制代码
<?php
 
$str= file_get_contents("3.txt");//将文件中的内容读成字符串
$str1=explode("\n",$str);//按换行进行拆分//单引号是转义字符,所以必须使用双引号
 
$data = [];
$count = count($str1);
$page = $_GET['page'];
$limit = $_GET['limit'];
$firstIndex=($page-1)*$limit;
$new = array_slice($str1,$firstIndex,$limit); 
$data1 = [];
$i = 0;
    foreach($new 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);
 
?>

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
zoenbo + 1 + 1 谢谢@Thanks!

查看全部评分

 楼主| zoenbo 发表于 2020-12-1 08:28
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-26 11:40

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表