Sunday, 18 August 2013

Using json encode

Using json encode

I am trying to use json encode for the first time and need some insight to
what I am doing wrong.
It should look like this:-
{ teams : [ ["2147483647", "9"],["2147483647", "6"],["2147483647",
"4"],["11", "2147483647"],["5", "2147483647"],["12", "8"],["10",
"3"],["2147483647", "7"], ], results : [ [ [[0, 1],[0, 1],[0, 1],[1,
0],[1, 0],[0, 0],[0, 0],[0, 1],], [[0, 0],[0, 0],[0, 0],[0, 0],], [[0,
0],[0, 0],], [[0, 0],[0, 0]] ] ] }
But the data being returned looks like this:-
{"teams":[["2147483647","10","5","12","11","2147483647","2147483647","2147483647"],["7","3","2147483647","8","2147483647","4","6","9"]],"results":[["0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0"]]}
Code:
public function getAutoCompleteData($tournID,$db) {
$max = $this -> max($tournID);
$one = $this -> tourn_info("1on1",$tournID);
$total_matches = $max;
$after_matches = $max / 2;
$matches = $db->query($this -> select("*", "matches",
"leagueID='{$tournID}' AND league='tourn'"));
while($row = $db->fetchAssoc($matches)) {
$clan1 = $this -> getname($row['clan1'], $tournID,
"tourn", $ac = NULL, 1 ,1, $wc2 = 0);
$clan2 = $this -> getname($row['clan2'], $tournID,
"tourn", $ac = NULL, 1 ,1, $wc2 = 1);
if($row['matchno'] <= $after_matches) {
$clan_one[] = $row['clan1'];
$clan_two[] = $row['clan2'];
$score_one[]= $row['score1'];
$score_two[]= $row['score2'];
}
}
$data = array(
'teams' => array($clan_one,$clan_two),
'results' => array($score_one,$score_two),
);
return $data;
}
Where it shows teams, it should close the bracket "]" every two teams?
Hope someone can help,
thank you!

No comments:

Post a Comment