display data with php and then sort with JSON

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • realin
    Contributor
    • Feb 2007
    • 254

    display data with php and then sort with JSON

    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=a rray(

    0=> array('title'=> 'Browser Plugin',
    'desc'=>'descri ption',
    'thumb'=>'http://',
    'link'=>'http://',
    'popular'=>'1',
    'timestamp'=>ti me(),
    'weight'=>'225k b',
    'category'=>'to ols'
    ),
    1=>array('title '=>'XML RSS Feed',
    'desc'=>'Descri ption',
    'thumb'=>'http://',
    'link'=>'http://',
    'popular'=>'2',
    'timestamp'=>ti me(),
    'weight'=>'215k b',
    'category'=>'to ols'
    )
    );[/PHP]

    thanks in advance..
    regards
    Realin !
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    So you want to generate JSON using PHP?

    Comment

    • realin
      Contributor
      • Feb 2007
      • 254

      #3
      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 !

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        To "transfer" it to the client-side, just use PHP to set the JSON to a JavaScript variable:
        Code:
        var json = <?php ... ?>;

        Comment

        • rnd me
          Recognized Expert Contributor
          • Jun 2007
          • 427

          #5
          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/87256B280015193 F87256C8D00514F A4 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.

          Comment

          • realin
            Contributor
            • Feb 2007
            • 254

            #6
            thanks a lot guys..
            will try and revert..

            Comment

            Working...