Re: changing order of items

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

 



afan pasalic 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




If I understand you right the problem is because you are showing a list of items with the status of todo and there are other items with a status of done, that if shown would have a priority in between the the ones with a status of todo. So if you simply swithch the priority value with the next record up in the priority order, it may not move because of unseen items with the done status.

I have had this problem before but in much different type of application. Basically you have several "groups" of records in the same table and you want to sort them independent of each other. What I have done is to specify what field(s) in the table define each group. In my case I have often had 1 2 or even 3 fields needed to define the groups. In your case it is just the todo / done status field. What I do is have the up and down arrow and have the link pass the ID of the item I want to move, the sort order value(priority in your case), the value(s) of the group field(s) and the direction I want to move the item. So the url for the move button would be something like this....

Status ToDo = 1
Status Done = 2
ID of Record to move is say 34
priority of record 34 is say 21
Record has a status of ToDo.


Move.php?ID=34&Order=21&Status=1&Move=Up

Then the move function does something like this.....

if($Move == 'Up){
  $query = "SELECT ID, Priority FROM `todolist \n";
  $query .= "WHERE `Priority` < '$Order' AND `Status` = '$Status' \n";
  $query .= "ORDER BY `Priority` DESC \n";
  $query .= "LIMIT 1 \n";
}else{
  $query = "SELECT ID, Priority FROM `todolist \n";
  $query .= "WHERE `Priority` > '$Order' AND `Status` = '$Status' \n";
  $query .= "ORDER BY `Priority` \n";
  $query .= "LIMIT 1 \n";
}
run query....
$TempID = $row['ID'];
$TempPriority = $row['Priority'];

$query = "UPDATE `todolist` SET `Priority` = '$Order' \n";
$query .= "WHERE `ID` = '$TempID' "
run query....
$query = "UPDATE `todolist` SET `Priority` = '$TempPriority' \n";
$query .= "WHERE `ID` = '$ID' "
run query...












--
Chris W
KE5GIX

"Protect your digital freedom and privacy, eliminate DRM,
learn more at http://www.defectivebydesign.org/what_is_drm";

Ham Radio Repeater Database.
http://hrrdb.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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