Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
1  
Did you try searching? stackoverflow.com/questions/5503900/… (amongst others) –  nnnnnn May 13 '13 at 12:39
    
also see here stackoverflow.com/questions/7104024/… –  PSR May 13 '13 at 12:39
    
Yeah I tried those except one, now I'll try the left one. –  user1845827 May 13 '13 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> –  user1845827 May 13 '13 at 12:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.