Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无重复内容的自动更新_Php_Jquery_Ajax_Wordpress - Fatal编程技术网

Php 无重复内容的自动更新

Php 无重复内容的自动更新,php,jquery,ajax,wordpress,Php,Jquery,Ajax,Wordpress,我创建了一个短代码,它基本上输出一个匹配结果列表。这些匹配结果由一个JSON脚本解析,该脚本连接到服务器上的cron作业,每5分钟更新一次。我不想让人们自己刷新浏览器,而是想知道如何使用AJAX、Jquery自动更新,而不复制匹配 简短代码如下所示: [resultpage] 短码功能: function resultpage() { $output = ''; $output .= '<div id="content">'; $outp

我创建了一个短代码,它基本上输出一个匹配结果列表。这些匹配结果由一个JSON脚本解析,该脚本连接到服务器上的cron作业,每5分钟更新一次。我不想让人们自己刷新浏览器,而是想知道如何使用AJAX、Jquery自动更新,而不复制匹配

简短代码如下所示:

[resultpage]
短码功能:

function resultpage() {



    $output = '';



    $output .= '<div id="content">';
        $output .= '<div id="part-1">';

        $output .= getgames("lol");


        $output .= '</div>';
       $output .= ' <div id="part-2">';
       $output .= getgames("counterstrike");
       $output .= ' </div>';
       $output .= ' <div id="part-3">';
       $output .= getgames("dota2");
       $output .= ' </div>';
       $output .= ' <div id="part-4">';
       $output .= getgames("hearthstone");
       $output .= ' </div>';
    $output .= '</div>';




return $output;
}

getGames输出是什么样子的?您是否将post数据存储在任何属性中?您在实现ajax方面做了哪些工作?问题非常广泛。我添加了getgames函数。它基本上只是包含游戏信息的循环div。如果你不想重复,你需要一种方法,通过指定一些id或时间戳作为数据属性来知道页面中已经有什么。另外,如何跟踪json文件中的内容?或者它是一个连接到db的php脚本?这里有太多的未知数我创建了一个api,它可以刮取数据并将其放入JSON文件中,当cron作业在服务器中运行时,JSON脚本每5分钟更新一次。每个匹配都有一个匹配id,可以通过$live->match_id访问。我只是没有使用它,因为我对AJAX和Jquery之类的东西没有太多经验。我真的不知道如何使用json文件。db表可能会更好。除非数据的寿命很短,并且您计划定期覆盖该文件
function getgames($thegame) {
$json = file_get_contents('JSON URL');
$obj = json_decode($json);
$livegames = $obj->live;  


$output = '';

foreach($livegames as $live){



        if ($live->game == $thegame) {
            $teamarray = returnteam($live->{'team 1'}->name, $live->{'team 2'}->name);

        if ($live->{'team 1'}->score == "") {
            $score1 = '0';
        }else {
            $score1 = $live->{'team 1'}->score;
        }
        if ($live->{'team 2'}->score == "") {
            $score2 = '0';
        } else {
            $score2 = $live->{'team 2'}->score;
        }



        $output .= '<div class="result-in-month">';

        $output .= '<div class="result-date">';
        $output .= $live->{'live in'};
        $output .= '</div>';
                $output .= '<div class="result-match-team-wrapper">';
                    $output .= '<span class="result-match-team left">';
                        $output .= $teamarray[0];

                    $output .= '</span>';
                    $output .= '<span class="result-match-versus">';
                        $output .= '<span class="result-match-score">'. $score1 .'</span><span class="result-match-separator">-</span><span class="result-match-score">'. $score2 .'</span>';
                    $output .= '</span>';
                    $output .= '<span class="result-match-team right">';
                    $output .= $teamarray[1];

                    $output .= '</span>';
                $output .= '</div>';
                $output .= '<div class="result-stream">';
                $output .= '<a href="'. $live->{'streams'}[0] .'">';
                $output .= 'Stream';
                $output .= '</a>';
                $output .= '</div>';

            $output .= '<div class="clear"></div>';

        $output .= '</div>';

    }
    }
}
{
    "live": [
    {
        "match_id": "65551",
        "has_vods": false,
        "game": "hearthstone",
        "team 1": {
            "score": "",
            "name": "ViCi Gaming",
            "bet": "39%"
        },
        "team 2": {
            "score": "",
            "name": "ZhanQi TV",
            "bet": "61%"
        },
        "live in": "Live",
        "title": "ViCi Gaming... 39% vs 61% ZhanQi TV",
        "url": "",
        "tounament": "http://www.gosugamers.net/",
        "simple_title": "ViCi Gaming... vs ZhanQi TV",
        "streams": [
            "http://www.twitch.tv/widgets/live_embed_player.swf?channel=Curemew"
        ]
    },
    {
        "match_id": "64907",
        "has_vods": false,
        "game": "dota2",
        "team 1": {
            "score": "",
            "name": "Summoner's Rift",
            "bet": "19%"
        },
        "team 2": {
            "score": "",
            "name": "Thundercats!",
            "bet": "12%"
        },
        "live in": "Live",
        "title": "Summoner's Rift 19% vs 12% Thundercats!",
        "url": "",
        "tounament": "http://www.gosugamers.net/",
        "simple_title": "Summoner's Rift vs Thundercats!",
        "streams": [
            "http://www.majorleaguegaming.com/player/embed/joinDOTA?autoplay=0"
        ]
    }
    ]
}