Is there way to parse JSON like this from MySQL - php

I want to create a PHP API from server to parse JSON to Android
but never mind of that.
The main problem is how can I code this
This is my PHP code
<?php
include 'includes/conn.php';
$sql = "SELECT * FROM positions ORDER BY priority ASC";
$res = array();
$query = $conn->query($sql);
while($row = $query->fetch_assoc()){
$csql = "SELECT * FROM candidates WHERE position_id='".$row['id']."'";
$cquery = $conn->query($csql);
$cs = array(
'pos_id' => $row['id'],
'pos_des' => $row['description'],
'max_votes' => $row['max_vote']);
while($crow = $cquery->fetch_assoc()){
$fe = array(
'candidates' => array(
'id' => $crow['id'],
'pos_id' => $crow['position_id'],
'firstname' => $crow['firstname'],
'lastname' => $crow['lastname'],
'photo' => $crow['photo'],
'platform' => $crow['platform']
array_push($cs,fe);
)
);
}
array_push($res,$cs);
}
echo json_encode($res);
?>
Now its working fine but instead
of this
[{
"pos_id": "1",
"pos_des": "Reprisentative",
"max_votes": "4",
"candidates": {
"id": "1",
"pos_id": "1",
"firstname": "G-9-JAY",
"lastname": "MCARTHUR",
"photo": "",
"platform": ""
}
},
{
"pos_id": "1",
"pos_des": "Reprisentative",
"max_votes": "4",
"candidates": {
"id": "2",
"pos_id": "1",
"firstname": "G-10-JOHN",
"lastname": "MARTIN",
"photo": "",
"platform": ""
}
},
{
"pos_id": "1",
"pos_des": "Reprisentative",
"max_votes": "4",
"candidates": {
"id": "5",
"pos_id": "1",
"firstname": "GRADE 7",
"lastname": "Lang ya",
"photo": "",
"platform": ""
}
},
{
"pos_id": "2",
"pos_des": "President",
"max_votes": "1",
"candidates": {
"id": "3",
"pos_id": "2",
"firstname": "User",
"lastname": "Name",
"photo": "",
"platform": ""
}
},
{
"pos_id": "2",
"pos_des": "President",
"max_votes": "1",
"candidates": {
"id": "4",
"pos_id": "2",
"firstname": "TEST",
"lastname": "USER",
"photo": "",
"platform": ""
}
}
]
I want this result
[{
"pos_id": "1",
"pos_des": "Reprisentative",
"max_votes": "4",
"candidates": [{
"id": "1",
"pos_id": "1",
"firstname": "G-9-JAY",
"lastname": "MCARTHUR",
"photo": "",
"platform": ""
}, {
"id": "2",
"pos_id": "1",
"firstname": "G-10-JOHN",
"lastname": "MARTIN",
"photo": "",
"platform": ""
}, {
"id": "5",
"pos_id": "1",
"firstname": "GRADE 7",
"lastname": "Lang ya",
"photo": "",
"platform": ""
}]
},
{
"pos_id": "2",
"pos_des": "President",
"max_votes": "1",
"candidates": [{
"id": "3",
"pos_id": "2",
"firstname": "User",
"lastname": "Name",
"photo": "",
"platform": ""
}, {
"id": "4",
"pos_id": "2",
"firstname": "TEST",
"lastname": "USER",
"photo": "",
"platform": ""
}]
}
]
Summary: I want The user to place in what pos_id he/she assign to the positions for example MARTIN is a running in president so MARTIN should show in President Position
How can I achieve this?

you should push onto $cs['candidates'], not create a separate array with candidates as the key for each candidate.
$cs = array(
'pos_id' => $row['id'],
'pos_des' => $row['description'],
'max_votes' => $row['max_vote'],
'candidates' => array());
while($crow = $cquery->fetch_assoc()){
$cs['candidates'][] = array(
'id' => $crow['id'],
'pos_id' => $crow['position_id'],
'firstname' => $crow['firstname'],
'lastname' => $crow['lastname'],
'photo' => $crow['photo'],
'platform' => $crow['platform']
);
}

Related

Parsing (3rd) Nested JSON with PHP

I am trying to parse following JSON with PHP but at the very last level ("bank") having some issues, following is the information:
JSON:
{
"loan": {
"fu": "1046",
"vb": "84",
"loan_type": "1",
"type_cocg": "14",
"meeting_place": "PLACE",
"meeting_date": "2019-05-29",
"creation_date": "2019-05-29 12:49:53",
"user_id": "1001-1556",
"member": [{
"mem_id": "1",
"name": "FIRST MEMBER",
"parentage": "PARENTAGE",
"cnic": "3393399393393",
"gender": "1",
"dob": "1994-05-29",
"marital_status": "1",
"spouse_name": "SPOUSE",
"spouse_cnic": "9939439939393",
"pres_address": "PRES ADDRESS",
"perma_address": "PERMA ADDRESS",
"mother_name": "MOTHER NAME",
"cell": "94494944949",
"loan_amount": "30000",
"network": "1",
"sim_ownership": "2",
"co_status": "3",
"occupation_category": "2",
"agri_occ": "null",
"nonagri_occ": "3",
"education": "1",
"disability": "2",
"religion": "6",
"head": "2",
"purpose": "2",
"repayment_mode": "null",
"duration": "4",
"purpose_ent": "null",
"purpose_agri": "null",
"area_unit": "2",
"agri_investment": "",
"agri_expense": "",
"purpose_livestock": "3",
"loan_id_mem": "1",
"monthly_income": "15000",
"monthly_expense": "2000",
"monthly_saving": "13000",
"yearly_saving": "156000",
"male": "2",
"female": "2",
"children": "2",
"cow": "2",
"buffalo": "2",
"goat": "2",
"sheep": "2",
"agri_area_unit": "1",
"land_own": "3",
"land_lease": "3",
"house_own": "3",
"house_rent": "3",
"caste": "CASTE",
"active_loan": "1",
"bank": [{
"id": "1",
"loan_id": "1",
"loan_mem_id": "1",
"bank_id": "1",
"bank_loan": "",
"bank_remaining": "2000",
"purpose": "1",
"purpose_agri": "16",
"purpose_livestock": "null",
"purpose_ent": "null"
}, {
"id": "2",
"loan_id": "1",
"loan_mem_id": "1",
"bank_id": "6",
"bank_loan": "",
"bank_remaining": "500",
"purpose": "3",
"purpose_agri": "16",
"purpose_livestock": "null",
"purpose_ent": "14"
}]
}, {
"mem_id": "2",
"name": "SECOND MEMBER",
"parentage": "PARENTAGE",
"cnic": "3939939393399",
"gender": "1",
"dob": "1994-05-29",
"marital_status": "1",
"spouse_name": "SPOUSE",
"spouse_cnic": "4949949494999",
"pres_address": "ADDRESS",
"perma_address": "ADDRESS",
"mother_name": "MOTHER",
"cell": "49494949494",
"loan_amount": "20000",
"network": "1",
"sim_ownership": "2",
"co_status": "2",
"occupation_category": "2",
"agri_occ": "null",
"nonagri_occ": "2",
"education": "1",
"disability": "1",
"religion": "1",
"head": "1",
"purpose": "1",
"repayment_mode": "null",
"duration": "3",
"purpose_ent": "null",
"purpose_agri": "16",
"area_unit": "1",
"agri_investment": "1500",
"agri_expense": "2000",
"purpose_livestock": "3",
"loan_id_mem": "1",
"monthly_income": "15000",
"monthly_expense": "200",
"monthly_saving": "14800",
"yearly_saving": "177600",
"male": "0",
"female": "0",
"children": "2",
"cow": "2",
"buffalo": "2",
"goat": "2",
"sheep": "2",
"agri_area_unit": "1",
"land_own": "3",
"land_lease": "3",
"house_own": "3",
"house_rent": "2",
"caste": "CASTE 2",
"active_loan": "1",
"bank": [{
"id": "3",
"loan_id": "1",
"loan_mem_id": "2",
"bank_id": "6",
"bank_loan": "",
"bank_remaining": "300",
"purpose": "1",
"purpose_agri": "43",
"purpose_livestock": "null",
"purpose_ent": "null"
}]
}]
}
}
PHP code:
$json = json_decode($content, true);
$json['loan']['fu']; // This works !
foreach($json['loan']['member'] as $item) {
$name = $item['name']; // This works !
foreach($json['loan']['member']['bank'] as $bank_item) { // THIS DOES NOT WORKS!
}
}
The last foreach loop gives out en error saying:
Notice: Undefined index: bank
Are there any clues as to what might be causing the issue, or is there some improved way of parsing the same JSON, that would be very helpful.
Your json parsing is fine. your accessing is missing index.
As the "bank" is inside an array of "member" you should access as $json['loan']['member'][0]['bank'] (the 0 is hard coded - you can switch for 1 also).
If you use for then you should do:
foreach($json['loan']['member'] as $item) {
$name = $item['name']; // This works !
foreach($item['bank'] as $bank_item) { // use $item
}
}
Use only a single foreach() and get the bank element value. If you further need to loop on bank element then you can use another foreach()
$json = json_decode($content, true);
foreach($json['loan']['member'] as $item) {
print_r($item['bank']);
foreach($item['bank'] as $bank_item) {
echo $bank_item;
}
}
DEMO: https://3v4l.org/qB8mV
You have missed that member is also multidimensional array
$json = json_decode($content, true);
/*
echo "<pre>";
print_r($json);
echo "</pre>";*/
foreach($json['loan']['member'] as $item => $value) {
$name = $value['name']; // This works !
foreach($json['loan']['member'][$item]['bank'] as $bank_item) { // THIS DOES NOT WORKS!
print_r($bank_item);
}
}
You can use array_walk_recursive() function also
$json = json_decode($content, true);
$i=0;
foreach($json['loan']['member'] as $item) {
array_walk_recursive($json['loan']['member'][$i]['bank'], function($value,$key) {
echo $key.' :'.$value ." \n";
});
$i++;
}
DEMO : https://3v4l.org/KDR6V

how to parse the json using php? [duplicate]

This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 5 years ago.
{
"result": "success",
"clientid": "1",
"serviceid": null,
"pid": null,
"domain": null,
"totalresults": "2",
"startnumber": 0,
"numreturned": 2,
"products": {
"product": [
{
"id": "1",
"clientid": "1",
"orderid": "1",
"pid": "1",
"regdate": "2015-01-01",
"name": "Starter",
"translated_name": "Starter",
"groupname": "Shared Hosting",
"translated_groupname": "Shared Hosting",
"domain": "demodomain.com",
"dedicatedip": "",
"serverid": "1",
"servername": "Saturn",
"serverip": "1.2.3.4",
"serverhostname": "saturn.example.com",
"suspensionreason": "",
"firstpaymentamount": "12.95",
"recurringamount": "12.95",
"paymentmethod": "authorize",
"paymentmethodname": "Credit Card",
"billingcycle": "Monthly",
"nextduedate": "2016-11-25",
"status": "Terminated",
"username": "demodoma",
"password": "xxxxxxxx",
"subscriptionid": "",
"promoid": "0",
"overideautosuspend": "",
"overidesuspenduntil": "0000-00-00",
"ns1": "",
"ns2": "",
"assignedips": "",
"notes": "",
"diskusage": "0",
"disklimit": "0",
"bwusage": "0",
"bwlimit": "0",
"lastupdate": "0000-00-00 00:00:00",
"customfields": {
"customfield": []
},
"configoptions": {
"configoption": []
}
},
{
"id": "2",
"clientid": "1",
"orderid": "2",
"pid": "3",
"regdate": "2015-05-20",
"name": "Plus",
"translated_name": "Plus",
"groupname": "Shared Hosting",
"translated_groupname": "Shared Hosting",
"domain": "demodomain2.net",
"dedicatedip": "",
"serverid": "2",
"servername": "Pluto",
"serverip": "2.3.4.5",
"serverhostname": "pluto.example.com",
"suspensionreason": "",
"firstpaymentamount": "24.95",
"recurringamount": "24.95",
"paymentmethod": "paypal",
"paymentmethodname": "PayPal",
"billingcycle": "Monthly",
"nextduedate": "2017-01-20",
"status": "Active",
"username": "demodom2",
"password": "xxxxxxxx",
"subscriptionid": "",
"promoid": "0",
"overideautosuspend": "",
"overidesuspenduntil": "0000-00-00",
"ns1": "",
"ns2": "",
"assignedips": "",
"notes": "",
"diskusage": "0",
"disklimit": "0",
"bwusage": "0",
"bwlimit": "0",
"lastupdate": "0000-00-00 00:00:00",
"customfields": {
"customfield": []
},
"configoptions": {
"configoption": [
{
"id": "1",
"option": "Sample Config Option",
"type": "dropdown",
"value": "Selected option value"
}
]
}
}
]
}
}
How can i parse the product details from json
You can use json decode function of php to make object then fetch data from object.
$data = 'write your json response here';
$return = json_decode($data);
print_r($return);
echo $return->result;

How to merge two JSON under an Array in PHP

I get details from the user through HTML form, and onclick the form submission, I run the php file, save2json.php, which retrieves from HTML form, and posts it as JSON in the file appointments.json.
save2json.php
$formdata = array(
$_POST['doctor'] => array(
'name'=> $_POST['name'],
'phone'=> $_POST['phone'],
'bday'=> $_POST['bday'],
'datepicker'=> $_POST['datepicker'],
)
);
$filetxt = 'appointments.json';
$arr_data = array();
if(file_exists($filetxt))
{
$jsondata = file_get_contents($filetxt);
$arr_data = json_decode($jsondata, true);
}
$arr_data[] = $formdata;
$jsondata = json_encode($arr_data, JSON_PRETTY_PRINT);
if(file_put_contents('appointments.json', $jsondata))
What I get: [appointments.json]
[{
"Doctor #3": {
"name": "0",
"phone": "0",
"bday": "0",
"datepicker": "0"
}
}, {
"Doctor #3": {
"name": "1",
"phone": "1",
"bday": "1",
"datepicker": "1"
}
}, {
"Doctor #1": {
"name": "2",
"phone": "2",
"bday": "2",
"datepicker": "2"
}
}, {
"Doctor #2": {
"name": "3",
"phone": "3",
"bday": "3",
"datepicker": "3"
}
}]
What I want: [appointments.json]
[{
"Doctor #3": [{
"name": "0",
"phone": "0",
"bday": "0",
"datepicker": "0"
},
{
"name": "1",
"phone": "1",
"bday": "1",
"datepicker": "1"
}
],
"Doctor #1": {
"name": "2",
"phone": "2",
"bday": "2",
"datepicker": "2"
},
"Doctor #2": {
"name": "3",
"phone": "3",
"bday": "3",
"datepicker": "3"
}
}]
If it is under same doctor, I want to make both objects come under the same array. And if it isn't like Doctor 1 and Doctor 2, in this case, I want them as separate apart from Doctor 3 array.
Thanks in Advance :)
This is the first attempt to put it inside the doctor array key:
<?php
// build the array
$docDetails = array(
'name'=> $_POST['name'],
'phone'=> $_POST['phone'],
'bday'=> $_POST['bday'],
'datepicker'=> $_POST['datepicker'],
);
// get the file's content as an array.
$filetxt = 'appointments.json';
if(file_exists($filetxt))
$arr_data = json_decode(file_get_contents($filetxt), true);
else
$arr_data = array();
$arr_data[$_POST['doctor']][] = $docDetails;
?>

php JSON data structure for angular app

I am trying to format the a mysql response into a array of objects so that Angular can easily traverse the data.
mysql result:
[{
"FIAccountsID": "99",
"AccountName": "",
"AccountCustomName": "Brothers",
"AccountNumber": "99-123123123",
"AccountTypeName": "IRA",
"FinancialInstName": "Testes",
"FinancialInstID": "9",
"UserID": "1",
"ofxStatusCode": "500",
"UserAccountID": "09128-vc-12",
"FirstName": "Someones",
"LastName": "Name",
"Status": "1"
},
{
"FIAccountsID": "99",
"AccountName": "",
"AccountCustomName": "Brothers",
"AccountNumber": "99-123123123",
"AccountTypeName": "IRA",
"FinancialInstName": "Testes",
"FinancialInstID": "9",
"UserID": "1",
"ofxStatusCode": "500",
"UserAccountID": "09128-vc-12",
"FirstName": "Someones",
"LastName": "Name",
"Status": "2"
},
{
"FIAccountsID": "100",
"AccountName": "",
"AccountCustomName": "Brothers",
"AccountNumber": "99-123123123",
"AccountTypeName": "IRA",
"FinancialInstName": "Testes",
"FinancialInstID": "9",
"UserID": "1",
"ofxStatusCode": "500",
"UserAccountID": "09128-vc-12",
"FirstName": "Someones",
"LastName": "Name",
"Status": "1"
},
{
"FIAccountsID": "100",
"AccountName": "",
"AccountCustomName": "Brothers",
"AccountNumber": "99-123123123",
"AccountTypeName": "IRA",
"FinancialInstName": "Testes",
"FinancialInstID": "9",
"UserID": "1",
"ofxStatusCode": "500",
"UserAccountID": "09128-vc-12",
"FirstName": "Someones",
"LastName": "Name",
"Status": "2"
},
{
"FIAccountsID": "101",
"AccountName": "",
"AccountCustomName": "Brothers",
"AccountNumber": "99-123123123",
"AccountTypeName": "IRA",
"FinancialInstName": "Testes",
"FinancialInstID": "9",
"UserID": "1",
"ofxStatusCode": "500",
"UserAccountID": "09128-vc-12",
"FirstName": "Someones",
"LastName": "Name",
"Status": "1"
},
{
"FIAccountsID": "101",
"AccountName": "",
"AccountCustomName": "Brothers",
"AccountNumber": "99-123123123",
"AccountTypeName": "IRA",
"FinancialInstName": "Testes",
"FinancialInstID": "9",
"UserID": "1",
"ofxStatusCode": "500",
"UserAccountID": "09128-vc-12",
"FirstName": "Someones",
"LastName": "Name",
"Status": "2"
},
{
"FIAccountsID": "102",
"AccountName": "",
"AccountCustomName": "Brothers",
"AccountNumber": "99-123123123",
"AccountTypeName": "IRA",
"FinancialInstName": "Testes",
"FinancialInstID": "9",
"UserID": "1",
"ofxStatusCode": "500",
"UserAccountID": "09128-vc-12",
"FirstName": "Someones",
"LastName": "Name",
"Status": "1"
},
{
"FIAccountsID": "102",
"AccountName": "",
"AccountCustomName": "Brothers",
"AccountNumber": "99-123123123",
"AccountTypeName": "IRA",
"FinancialInstName": "Testes",
"FinancialInstID": "9",
"UserID": "1",
"ofxStatusCode": "500",
"UserAccountID": "09128-vc-12",
"FirstName": "Someones",
"LastName": "Name",
"Status": "2"
},
{
"FIAccountsID": "103",
"AccountName": "",
"AccountCustomName": "Brothers",
"AccountNumber": "99-123123123",
"AccountTypeName": "IRA",
"FinancialInstName": "Testes",
"FinancialInstID": "9",
"UserID": "1",
"ofxStatusCode": "500",
"UserAccountID": "09128-vc-12",
"FirstName": "Someones",
"LastName": "Name",
"Status": "1"
},
{
"FIAccountsID": "103",
"AccountName": "",
"AccountCustomName": "Brothers",
"AccountNumber": "99-123123123",
"AccountTypeName": "IRA",
"FinancialInstName": "Testes",
"FinancialInstID": "9",
"UserID": "1",
"ofxStatusCode": "500",
"UserAccountID": "09128-vc-12",
"FirstName": "Someones",
"LastName": "Name",
"Status": "2"
}......
here it the PHP:
while($row = mysqli_fetch_assoc($result))
{
$uid = $row['UserID'];
$name = $row['FirstName'].' '.$row['LastName'];
$fiid = $row['FinancialInstID'];
$fi = $row['FinancialInstName'];
$acctID = $row['FIAccountsID'];
$rows[$uid]['name'] = $name;
$rows[$uid]['uid'] = $uid;
$rows[$uid]['fi'][$fiid]['name'] = $fi;
$rows[$uid]['fi'][$fiid]['acct'][$acctID]['name'] = $row['AccountCustomName'];
}
print json_encode($rows);
this is what i get:
{
"1": {
"name": "Some Name",
"uid": "1",
"fi": {
"9": {
"name": "Testes",
"accts": {
"99": {
"name": "name 1"
},
"100": {
"name": "name 2"
},
"103": {
"name": "name 3"
}
}
}
}
},
"2": {
"name": "Another Name",
"uid": "2",
"fi": {
"7": {
"name": "Trevor's Brokerage House",
"accts": {
"1": {
"name": "Sally's 401k Account"
},
"2": {
"name": "retirement"
},
"3": {
"name": "Some other account"
..........
desired result:
[
{
"users": [
{
"name": "Some Name",
"uid": "1",
"fi": [
{
"name": "Testes",
"acct": [
{
"name": "name 1"
},
{
"name": "name 2"
},
{
"name": "name 3"
}
]
}
]
},
{
"name": "Another Name",
"uid": "2",
"fi": [
{
"name": "Trevor's Brokerage House",
"acct": [
{
"name": "Sally's 401k Account"
},
{
"name": "retirement"
},
{
"name": "Some other account"
..........
I want to know how to have the data structure without the unique keys prefixing the nested arrays
The thing is that if you define keys, json_encode will read them. If you don't want keys, declare the array without them. So, what you need to do is to structure your array according to you desired output.
But the way your data is arranged make it somewhat hard to format it properly. The solution I can see is to do what you're already doing:
while($row = mysqli_fetch_assoc($result))
{
$uid = $row['UserID'];
$name = $row['FirstName'].' '.$row['LastName'];
$fiid = $row['FinancialInstID'];
$fi = $row['FinancialInstName'];
$acctID = $row['FIAccountsID'];
$rows[$uid]['name'] = $name;
$rows[$uid]['uid'] = $uid;
$rows[$uid]['fi'][$fiid]['name'] = $fi;
$rows[$uid]['fi'][$fiid]['acct'][$acctID]['name'] = $row['AccountCustomName'];
}
But then you revisit the array and remove all the keys using array_values:
foreach ($rows as $uid => $data)
{
foreach ($data['fi'] as $fiid => $fi)
{
$rows[$uid]['fi'][$fiid]['acct'] = array_values($fi['acct']);
}
$rows[$uid]['fi'] = array_values($rows[$uid]['fi']);
}
// Here you format the outer array:
$rows = array(array('users' => array_values($rows)));
Which gives a result like this:
[
{
"users": [
{
"name": "Someones Name",
"uid": "1",
"fi": [
{
"name": "Testes",
"acct": [
{
"name": "Brothers"
},
{
"name": "Brothers"
},
{
"name": "Brothers"
},
{
"name": "Brothers"
},
{
"name": "Brothers"
}
]
}
]
},
{
"name": "Someones Name",
"uid": "2",
"fi": [
{
"name": "Testes",
"acct": [
{
"name": "Brothers"
},
{
"name": "Brothers"
}
]
}
]
}
]
}
]

JSON decoding array

I have this JSON code:
{
"phrases": [
{
"phrases": [
{
"id": "33",
"text": "sasdsad",
"date": "2012-03-14 20:28:45",
"views": "0",
"ip": "64.191.90.5",
"reported": "0",
"strange": "0",
"lang": "en"
},
{
"id": "32",
"text": "que ondaa\r\n",
"date": "2012-03-14 20:27:45",
"views": "0",
"ip": "64.191.90.5",
"reported": "0",
"strange": "0",
"lang": "en"
},
{
"id": "31",
"text": "dsadssadsad",
"date": "2012-03-14 20:27:35",
"views": "0",
"ip": "64.191.90.5",
"reported": "0",
"strange": "0",
"lang": "en"
}
],
"details": {
"success": "true",
"phrase_id": "",
"phrase_text": "",
"phrase_date": ""
}
}
I don't really know what to do. I get some phrases vía MySQL, and pushes them to an array. This array is json_encoded() and gets printed.
$sth = $sql;
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
$sth = $sql;
$data = array(
"success" => "true",
"phrase_id" => "",
"phrase_text" => "",
"phrase_date" => "",
);
print json_encode($rows).json_encode($data);
and with jQuery I was trying to parse it, but I can't. This is the main problem.
function getPhrases(order,limit,last){
var req_url = ...;
$.getJSON(req_url, function(data) {
$.each(data.phrases, function(i, data) {
appendPhrase(data.text);
lastid = data.id;
});
$.each(data.details, function(i, data) {
$("#phrases-count").html(data.totalcount);
});
});
}
PS: I was doing this with "echo" but got some problems.
{
"phrases": [
{
"id": "33",
"text": "sasdsad",
"date": "2012-03-14 20:28:45",
"views": "0",
"ip": "64.191.90.5",
"lang": "en"
},
{
"id": "32",
"text": "que ondaa<br />",
"date": "2012-03-14 20:27:45",
"views": "0",
"ip": "64.191.90.5",
"lang": "en"
},
{
"id": "31",
"text": "dsadssadsad",
"date": "2012-03-14 20:27:35",
"views": "0",
"ip": "64.191.90.5",
"lang": "en"
}
],
"details": [
{
"totalcount": "3",
"logged_in": "false"
}
]
}
You can't simply combine these JSON arrays:
print json_encode($rows).json_encode($data);
Try this (attempt 2):
print json_encode( array('phrases' => $rows, 'details' => $data) );

Categories