0

I have an array in php, I took it in javascript using this variable

 <script>

   var myArray = <?php echo json_encode($id); ?>;

 </script>

here is a sample data loaded in the javascript variable

 var myArray = [{"product":"AMALFI COAST BISTRO WALKING","prod_id":179,"thumb":"/wp\/tangtours\/wp-content\/uploads\/2013\/04\/AMCWB_fi-148x106.jpg"},{"product":"ARGENTINA BIKING","prod_id":186,"thumb":"/wp\/tangtours\/wp-content\/uploads\/2013\/04\/ARGEB_fi-148x106.jpg"},{"product":"CHINA PRIVATE","prod_id":188,"thumb":"/wp\/tangtours\/wp-content\/uploads\/2013\/04\/CHNR2B_fi-148x106.jpg"},{"product":"BORDEAUX TO DORDOGNE BIKING","prod_id":191,"thumb":"/wp\/tangtours\/wp-content\/uploads\/2013\/04\/BDOBS_fi-148x106.jpg"},{"product":"AMERICAN WEST COAST BESPOKE","prod_id":198,"thumb":"/wp\/tangtours\/wp-content\/uploads\/2013\/04\/AWCB1_fi-148x106.jpg"},{"product":"BHUTAN PRIVATE","prod_id":195,"thumb":"/wp\/tangtours\/wp-content\/uploads\/2013\/04\/BTNR2B_fi-148x106.jpg"}];

All I have to do is to sort this content using jquery or javascript by product, prod_id and thumb.

is there any simple way to sort this content and print them in a div in Ascending and descending order using jquery or javascript?

this is a sample site http://www.butterfield.com/tripfinder/ of what I really need. please use sort by options on the right top, they used dojo to do it, and I am not much familiar with dojo anyway. thank you.

4
  • 1
    Did you try searching? stackoverflow.com/questions/5503900/… (amongst others) Commented May 13, 2013 at 12:39
  • also see here stackoverflow.com/questions/7104024/… Commented May 13, 2013 at 12:39
  • Yeah I tried those except one, now I'll try the left one. Commented May 13, 2013 at 12:45
  • Is it possible to print value in a div using these lines? <script> var array =[ ['12', ,'Smith',1],['13', 'Jones',2]]; array.sort(function(a, b){ var a1= a[1], b1= b[1]; if(a1== b1) return 0; return a1> b1? 1: -1; }); </script> Commented May 13, 2013 at 12:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.