Re: changing order of items

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, May 15, 2008 at 2:09 PM, afan pasalic <afan@xxxxxxxx> wrote:

> this one bugs me for a while. how to change order.
>
> I have a list of tasks. by status, task could be 1 (todo) or 0 (done) -
> status value stored in mysql. I can list tasks per status or all.
> order number is stored in mysql too.
> the easiest way to change order is to have form for each task where you
> will enter manually number and then submit (one submit button for whole
> form). but, if you change order number for any task you have to change
> then all order numbers "below" the task manually
>
> solution with "arrows" (or up/down buttons) where you click on arrow and
> the task switch the place with its "neighbor" is easy and fancy. Though,
> I get in trouble if, e.g. tasks 10, 11, 12, and 13 change status from 1
> to 0 and I have to move task 14 to place 6. I have to click first 4
> times (to switch places with tasks 13, 12, 11, and 10) - but nothing is
> actually happening on screen (of course) before start switching places
> with 9, 8, 7, and 6.
>
> how do you avoid this "gap"?
> what solution do you use at all?
>
> thanks for any help.
>
> -afan
>  <http://www.php.net/unsub.php>
>
>
I am assuming that each time you click the up or down arrow you are
re-loading the page (via a GET request).  A simple solution to this, would
be to adjust the URLs assigned to the up and down arrows to carry an extra
variable, the item either directly above or directly below the one selected,
and instead of doing whole-sale renumbering, create a swap function.  That
just swaps the position of the two items.

example:

<?php
$rows = get_items_in_list();
for ($i = 0 ; $i < count($rows); $i ++) {
  echo $rows[$i]['taskname']."&nbsp;";
  // create move up link
  if ($i > 0) {
    echo '<a
href="page.php?this='.rows[$i]['position'].'&other='.$rows[($i-1)]['position'].'">move
up</a>&nbsp;';
  }
  //create mode down link
  if ($i < (count($rows) -1)) {
    echo '<a
href="page.php?this='.rows[$i]['position'].'&other='.$rows[($i+1)]['position'].'">move
up</a><br/>';
  }
}
?>

Then your page would just have to watch for those two variables being set at
load and select the appropriate items in the database based on the order and
swap their two positions, this will allow you to handle gaps in the
positioning scheme, for example when you are only listing the status 1 items
and not all the items.

*note* The code above is completely off-the-cuff and not tested, don't blame
me if there are any bugs in it ;)

Regards,

Jason

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux