473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

display data with php and then sort with JSON

realin
254 100+
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
5 4572
acoder
16,027 Expert Mod 8TB
So you want to generate JSON using PHP?
Nov 6 '08 #2
realin
254 100+
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
16,027 Expert Mod 8TB
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
427 Expert 256MB
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
254 100+
thanks a lot guys..
will try and revert..
Nov 7 '08 #6

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

Similar topics

22
by: googlegroups | last post by:
I am playing with the XMLHTTPRequest method to perform client/server transactions. I have it set up right now so that when readyState is 4, it takes the XML and processes it. This works great until...
20
by: Luke Matuszewski | last post by:
Welcome As suggested i looked into JSON project and was amazed but... What about cyclical data structures - anybody was faced it in some project ? Is there any satisactional recomendation... ...
3
by: Rich | last post by:
Hi, I'm very, very new to javascript, so please bear with me if this is a silly question. My problem is this. I would like to some javascript connect to a URL on the same webserver and...
3
by: kpmassey | last post by:
I'm using javascript to construct large tables from an array of data, using ideas from: http://www.oreillynet.com/pub/a/javascript/2003/05/06/dannygoodman.html The data itself cannot be...
3
by: xhe | last post by:
I found Jason is a very handy data format for client/server communication. But I just met a problem as follows: I want to read the data replied from server in Jason format, the reply is like...
6
by: Jasper | last post by:
Hi, Maybe this is off-topic, but perhaps you can help. I'm looking for ideas on how to parse a data file. I dont know XML but I know it parses data in text format. I have a structured data...
4
by: avicalc | last post by:
I need help with the structure of a JavaScript program. My process is as follows: 1) Get JSON data via XMLHttpRequest. 2) When done with the above, process the JSON data which may take up to 3...
3
by: Steve Potter | last post by:
I'm working on a project to create a central administration interface for several websites located on different physical servers. You can think of the websites as a blog type application. My...
0
by: JonTwend | last post by:
I am working with the Twitter API and finding it great fun and generally easy to use. But I am having trouble getting to the data in the trends/current.json file. I am able to loop through the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.