samedi 11 juin 2016

get SyntaxError: Error #1132: Invalid JSON parse input when i send the value to php to restrict when getting data from MySQL with LIMIT

I am building an air app in flash cs6 using as3. I need to send the value of the Id to PHP so that I can choose which data have been shown and where the data will be displayed.

I have found how to get the data that has been displayed and which are not by entering the Id values into an array and take the highest or lowest value. but his problem is that when I send the data to php I get an error : SyntaxError: Error #1132: Invalid JSON parse input

here is my code:

var maxId:Number = 0;
var minId:Number = 18;
var phpVars:URLVariables = new URLVariables();
var phpFileReq:URLRequest = new URLRequest("http://localhost/social_media_1/timeline.php");
phpFileReq.method = URLRequestMethod.POST;
phpFileReq.data = phpVars;
var phpLoader:URLLoader = new URLLoader();
phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
phpVars.maxId = maxId;
phpVars.minId = minId;
phpLoader.load(phpFileReq);

bg2_mc.x = 0;
bg2_mc.y = 305;
addChild(bg2_mc);
timeline_mc.x = 0;
timeline_mc.y = 305;
addChild(timeline_mc);
sampul_mc.x = 0;
sampul_mc.y = 0;
addChild(sampul_mc);
fotoProfil_mc.x = 240;
fotoProfil_mc.y = 85;
addChild(fotoProfil_mc);
navigasi_mc.x = 0;
navigasi_mc.y = 170;
addChild(navigasi_mc);
tempatPost_mc.x = 0;
tempatPost_mc.y = 230;
addChild(tempatPost_mc);
tempatPost_mc.btn.gotoAndStop(2);
tombol1.x = tombol1.width/2;
tombol1.y = tombol1.height/2;
addChild(tombol1);
tombol2.x = tombol2.width/2;
tombol2.y = 100;
addChild(tombol2);

loadTimeline()

function loadTimeline(){
    var phpFileRequest:URLRequest = new URLRequest("http://localhost/social_media_1/timeline.php?action=load_timeline");
    var phpLoader:URLLoader = new URLLoader();
    phpLoader.dataFormat = URLLoaderDataFormat.TEXT;
    phpLoader.addEventListener(Event.COMPLETE, onCompleteLoadTimeline);
    phpLoader.load(phpFileRequest);
}

function onCompleteLoadTimeline(event:Event){
    var result:Object = JSON.parse(event.target.data);

    for (var i:int=0;i<=4;i++){
        tpostArr[i] = new t_post();
        var batas_mc:batas = new batas();

        tpostArr[i].foto.x = 52.50;
        tpostArr[i].foto.y = 52.50;

        tpostArr[i].nama.x = 120;
        tpostArr[i].nama.y = 20;

        tpostArr[i].postingan.x = 120;
        tpostArr[i].postingan.y = 55.15;
        tpostArr[i].postingan.wordWrap = true;
        tpostArr[i].postingan.autoSize = TextFieldAutoSize.LEFT;

        tpostArr[i].tombol_suka.x = 440;
        tpostArr[i].tombol_suka.y = 73;
        tpostArr[i].nama.text = result[i].timeline_name;
        tpostArr[i].postingan.text = result[i].timeline_post;
        batas_mc.x = 0;
        batas_mc.y = tpostArr[i].postingan.y + tpostArr[i].postingan.height + 20;
        tpostArr[i].addChild(batas_mc);
        idPrint.push(result[i].id);

        timeline_mc.addChild(tpostArr[i]);
        tpostArr[i].y = yPos;
        yPos = tpostArr[i].y+tpostArr[i].height;
        yPos +=5;
        maxId = Math.max.apply(null, idPrint);
        minId = Math.min.apply(null, idPrint);

        var phpVars:URLVariables = new URLVariables();
        var phpFileReq:URLRequest = new URLRequest("http://localhost/social_media_1/timeline.php");
        phpFileReq.method = URLRequestMethod.POST;
        phpFileReq.data = phpVars;

        phpVars.maxId = maxId;
        phpVars.minId = minId;
    }
}

here is my php code:

<?php
require_once "connect.php";
$action = isset($_GET['action'])?$_GET['action']:'';
$body_nama = array();
$body_postingan = array();
$total_likers = array();
$id = array();
$minId = URLDecode($_POST['minId']);

switch($action){
case 'posting':
posting();
break;
case 'like':
like();
break;
case 'delet_ini':
deletIni();
break;
case 'load_timeline':
loadTimeline();
break;
case 'load_timeline_baru':
loadTimelineBaru();
break;
}


function loadTimeline(){

global $minId;

$query_offset = "SELECT COUNT(*) FROM timeline_posts WHERE id > $minId";
$result_offset = mysql_query($query_offset);
$offset = mysql_result($result_offset,0);

echo $offset;

$jumlah = 10;
$sqldata = mysql_query("SELECT * FROM timeline_posts ORDER BY timeline_posts.id DESC LIMIT $offset,$jumlah");


$rows = array();
while($r = mysql_fetch_assoc($sqldata)) {
    $rows[] = $r;
}



echo json_encode($rows);

}

function loadTimelineBaru(){
$maxId = URLDecode($_POST['maxId']);


$query_load = "SELECT COUNT(*) FROM timeline_posts WHERE id > '$maxId'";
$result_load = mysql_query($query_load);
$jumlah = mysql_result($result_load,0);
$sqldata = mysql_query("SELECT * FROM timeline_posts ORDER BY timeline_posts.id ASC LIMIT '$jumlah'");

$rows = array();
while($r = mysql_fetch_assoc($sqldata)) {
    $rows[] = $r;
}

echo json_encode($rows);
}
?>

Aucun commentaire:

Enregistrer un commentaire