By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,363 Members | 1,470 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,363 IT Pros & Developers. It's quick & easy.

display data with php and then sort with JSON

realin
100+
P: 254
hiya guys,

Its been long i came here to discuss my problems. Hoep everything is same and i am gonna get quick reply :D

Well i have certain static data which i need to display using FastTemplate and then i want to use JSON to sort that data on the client side.

I wish i could do it with simple ajax, but i have to do it using json only as it has to be client side sorting for performance issues. For example i have this array, how do i do it, i am kinda stuck, just a little Hint would do ..

[PHP]$websiteTools=array(

0=> array('title'=>'Browser Plugin',
'desc'=>'description',
'thumb'=>'http://',
'link'=>'http://',
'popular'=>'1',
'timestamp'=>time(),
'weight'=>'225kb',
'category'=>'tools'
),
1=>array('title'=>'XML RSS Feed',
'desc'=>'Description',
'thumb'=>'http://',
'link'=>'http://',
'popular'=>'2',
'timestamp'=>time(),
'weight'=>'215kb',
'category'=>'tools'
)
);[/PHP]

thanks in advance..
regards
Realin !
Nov 6 '08 #1
Share this Question
Share on Google+
5 Replies


acoder
Expert Mod 15k+
P: 16,027
So you want to generate JSON using PHP?
Nov 6 '08 #2

realin
100+
P: 254
Of course generating JSON is the part of problem and that can be done using json_encode() method of php. But how do i transfer it to client side and then use json to sort the divs based on div ids or may be anyother sorting element. As if now i simply want to display this array on a HTML page, may be using JSON.

cheers !!
Realin !
Nov 7 '08 #3

acoder
Expert Mod 15k+
P: 16,027
To "transfer" it to the client-side, just use PHP to set the JSON to a JavaScript variable:
Expand|Select|Wrap|Line Numbers
  1. var json = <?php ... ?>;
Nov 7 '08 #4

rnd me
Expert 100+
P: 427
Arrays can be sorted using the ([1,5,2,3]).sort() method.

if you need to sort an array of objects, you will have to write a custom sort function.

see http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256C8D00514FA4 for more about that

you pass the actual data using JSONP, and you callback build the HTML from the data and sets the .innerHTML of a container div, or add the elements programatically though the DOM.
Nov 7 '08 #5

realin
100+
P: 254
thanks a lot guys..
will try and revert..
Nov 7 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.