Assigning column names in JSON server side code
Assigning column names in JSON server side code
gordyr
Posts: 35Questions: 0Answers: 0
I have come accress a need to have the JSON ouptut that that datatables spits out to have uniquely named column identifiers output along with the data. e.g. The standard server side script produces output like this:-
[code]
{
"sEcho":1,
"total":"1710",
"aaData":[
[
"Help",
"http:\/\/www.mysite.com\/wp-content\/uploads\/2011\/09\/dt_intfc4e732d1f1276d_4e76fab1e95bd.mp3?King_of_Spain_Entropy_02_Animals_Part_1.mp3",
"1784",
"3",
0,
null,
"0000-00-00 00:00:00"
],
[
"A Day In The Life",
"http:\/\/www.mysite.com\/wp-content\/uploads\/2011\/09\/dt_intfc4e732d1f1276d_4e76f5fc253a1.mp3?JenWood_Zeppelin.mp3",
"3573",
"3",
0,
null,
"0000-00-00 00:00:00"
]
}
[/code]
I need to give each column a name so that it outputs the following;-
[code]
{
"sEcho":1,
"total":"1710",
"aaData":[
[
name: "Help",
link: "http:\/\/www.mysite.com\/wp-content\/uploads\/2011\/09\/dt_intfc4e732d1f1276d_4e76fab1e95bd.mp3?King_of_Spain_Entropy_02_Animals_Part_1.mp3",
songid: "1784",
artistid: "3",
rating: 0,
favourite: null,
time: "0000-00-00 00:00:00"
]
}
[/code]
The JSON encoding part of my server side code is as follows:-
[code]
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i
[code]
{
"sEcho":1,
"total":"1710",
"aaData":[
[
"Help",
"http:\/\/www.mysite.com\/wp-content\/uploads\/2011\/09\/dt_intfc4e732d1f1276d_4e76fab1e95bd.mp3?King_of_Spain_Entropy_02_Animals_Part_1.mp3",
"1784",
"3",
0,
null,
"0000-00-00 00:00:00"
],
[
"A Day In The Life",
"http:\/\/www.mysite.com\/wp-content\/uploads\/2011\/09\/dt_intfc4e732d1f1276d_4e76f5fc253a1.mp3?JenWood_Zeppelin.mp3",
"3573",
"3",
0,
null,
"0000-00-00 00:00:00"
]
}
[/code]
I need to give each column a name so that it outputs the following;-
[code]
{
"sEcho":1,
"total":"1710",
"aaData":[
[
name: "Help",
link: "http:\/\/www.mysite.com\/wp-content\/uploads\/2011\/09\/dt_intfc4e732d1f1276d_4e76fab1e95bd.mp3?King_of_Spain_Entropy_02_Animals_Part_1.mp3",
songid: "1784",
artistid: "3",
rating: 0,
favourite: null,
time: "0000-00-00 00:00:00"
]
}
[/code]
The JSON encoding part of my server side code is as follows:-
[code]
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i
This discussion has been closed.
Replies
Allan