Page 1 of 1

Array Sorting!

Posted: Tue Feb 27, 2007 1:10 am
by wiseone
i got 4 divs in one page which holds contain in them... by default i hav set the sort order to win-xp, win-vista, mac-os-x & linux... i m allowing user to customize the way they want the order to be.. via scriptaculous (Sortable.create) function, when the user is done with the sort order, the script simply save the info in cookie, so next time when the user visits the website my script looks in the cookie for sort order n if its present then my default sort order is reset by user's sort-order.... n the page is rendered!

array #1 info comes from mysql database.. array #2 from users cookie i use explode("," , $sortorder) to store it in array #2...

Is there ne other way by which it can be achieved????? do i need to store the id and sortorder in the cookie or only sortorder will do??? i m really confused! n stuck for last 2 days...

thnx for your help!

Code: Select all

Array #1 (
  [0] => Array (
    [sortorder] => 1
    [id] => 3
    [name] => Windows XP
  )

  [1] => Array (
    [sortorder] => 2
    [id] => 4
    [name] => Windows Vista
  )

  [2] => Array (
    [sortorder] => 3
    [id] => 2
    [name] => Mac OSX
  )

  [3] => Array (
    [sortorder] => 4
    [id] => 1
    [name] => Linux
  )
)

Array #2 (
  [0] => Array (
    [sortorder] => 2
  )

  [1] => Array (
    [sortorder] => 1
  )

  [2] => Array (
    [sortorder] => 4
  )

  [3] => Array (
    [sortorder] => 3
  )
)

Posted: Tue Feb 27, 2007 7:48 am
by Begby
I think this will work. OrderArray is the array you are getting from you cookie, and the unsortedArray is the array you have with the operating systems.

Code: Select all

foreach( $orderArray as $order )
{
  $sortedArray[] = $unsortedArray[$order] ;
}