Welcome Guest, Not a member yet? Register   Sign In
Re-ordering result (rank)
#2

[eluser]Rick Jolly[/eluser]
This kind of thing is so easy to do with the help of javascript. You could let the user dynamically update the order, and when finished submit the changes to the database.

I've used scriptaculous to update the order of images using drag and drop. When the user submits the changes, scriptaculous posts an array of image ids in the current order. Then all I have to do is loop through the array and update the order:
Code:
// 'pic_ids' holds a string representing an ordered array of image ids like this: pics[]=2&pics;[]=3&pics;[]=1
$pic_ids = $this->input->post('pic_ids');
// parse_str($pic_ids) creates and assigns the pics array from the $pic_ids string.
parse_str($pic_ids);
if ($pics)
{
   $count = count($pics);
   for ($i = 0; $i < $count; $i++)
   {
      $this->db->where('pic_id', $pics[$i]);
      $this->db->update('pictures_table', array('picture_order' => $i));
   }
}

EDIT: Never mind the semicolons in the pics array example above - the forum is adding those.


Messages In This Thread
Re-ordering result (rank) - by El Forum - 09-26-2007, 09:09 AM
Re-ordering result (rank) - by El Forum - 09-26-2007, 11:34 AM
Re-ordering result (rank) - by El Forum - 09-26-2007, 01:34 PM
Re-ordering result (rank) - by El Forum - 09-26-2007, 01:58 PM
Re-ordering result (rank) - by El Forum - 09-26-2007, 02:18 PM
Re-ordering result (rank) - by El Forum - 09-26-2007, 02:32 PM
Re-ordering result (rank) - by El Forum - 09-26-2007, 03:33 PM
Re-ordering result (rank) - by El Forum - 09-27-2007, 07:43 AM
Re-ordering result (rank) - by El Forum - 09-27-2007, 08:17 AM
Re-ordering result (rank) - by El Forum - 09-27-2007, 09:03 AM
Re-ordering result (rank) - by El Forum - 09-27-2007, 09:20 AM
Re-ordering result (rank) - by El Forum - 09-27-2007, 01:05 PM
Re-ordering result (rank) - by El Forum - 09-27-2007, 01:30 PM



Theme © iAndrew 2016 - Forum software by © MyBB