ryeman98 Posted June 21, 2007 Share Posted June 21, 2007 Hi there. I'm creating something for another website and it works like this: There is a list of projects that need to be complete and staff can add and delete them, only problem is that when I try to move something up on the priority list, the number goes weird. The priority numbers are 1, 2, 3, 4 and 5. If I click to move something up, it will change the number to 0 (That's when I'm on any number) and when I try to move something down it doesn't change the number at all. Here's the code: <?php $id = addslashes($_POST['id']); $move = $_POST['move']; if ($move == "up") { $x = $_POST['priority']; $newpriority = $x-1; if ($_POST['priority'] == "1") { echo "This project is already at the top of the priority list!"; } elseif ($_POST['priority'] < "1") { echo "Something is wrong. Please contact Rye to fix it immediately!"; } else { $query_up = mysql_query("UPDATE projects SET priority='$newpriority' WHERE id='$id'") or die(mysql_error()); header('Location: http://www.somesite.com/project.php'); } } if ($move == "down") { $x = $_POST['priority']; $newpriority = $x+1; if ($_POST['priority'] == "5") { echo "This project is already at the bottom of the priority list!"; } elseif ($_POST['priority'] > "5") { echo "Something is wrong. Please contact Rye to fix it immediately!"; } else { $query_down = mysql_query("UPDATE projects SET priority='$newpriority' WHERE id='$id'") or die(mysql_query()); header('Location: http://www.somesite.com/project.php'); } } ?> Please help. Thanks! Rye Quote Link to comment https://forums.phpfreaks.com/topic/56582-wont-update-new-number/ Share on other sites More sharing options...
Barand Posted June 21, 2007 Share Posted June 21, 2007 Can see an obvious error, but if you move "3" up to "2", then current "2" should now bcome "3", so you need two updates. Quote Link to comment https://forums.phpfreaks.com/topic/56582-wont-update-new-number/#findComment-279459 Share on other sites More sharing options...
ryeman98 Posted June 21, 2007 Author Share Posted June 21, 2007 Can see an obvious error, but if you move "3" up to "2", then current "2" should now bcome "3", so you need two updates. I'm not quite sure I understand... Quote Link to comment https://forums.phpfreaks.com/topic/56582-wont-update-new-number/#findComment-279463 Share on other sites More sharing options...
Grego Posted June 21, 2007 Share Posted June 21, 2007 If you move "3" up to "2", there will be two entries under "2". The one before, and the updated one. Thus, you need to change the one that was originally "2" to "3". Quote Link to comment https://forums.phpfreaks.com/topic/56582-wont-update-new-number/#findComment-279465 Share on other sites More sharing options...
ryeman98 Posted June 21, 2007 Author Share Posted June 21, 2007 I don't know why but I still can't understand... What would I need to update again? Quote Link to comment https://forums.phpfreaks.com/topic/56582-wont-update-new-number/#findComment-279470 Share on other sites More sharing options...
Barand Posted June 21, 2007 Share Posted June 21, 2007 [pre] Start with Move C up to 2 A 1 A 1 B 2 C 2 C 3 B 2 <--- so you now need to change B to priority 3 D 4 D 4 E 5 E 5 [/pre] Quote Link to comment https://forums.phpfreaks.com/topic/56582-wont-update-new-number/#findComment-279475 Share on other sites More sharing options...
ryeman98 Posted June 21, 2007 Author Share Posted June 21, 2007 But there are going to be lots of entries, why can't I have some that are the same? Quote Link to comment https://forums.phpfreaks.com/topic/56582-wont-update-new-number/#findComment-279479 Share on other sites More sharing options...
Barand Posted June 21, 2007 Share Posted June 21, 2007 No reason, but if they are of equal priority it defeats the object of setting priorities, so why bother to move it up? But usually, if you move something up in a list, then something gets displaced downwards. Similarly, if you reduce the priority of an item, then it is implied that the one below rises in priority. Quote Link to comment https://forums.phpfreaks.com/topic/56582-wont-update-new-number/#findComment-279487 Share on other sites More sharing options...
ryeman98 Posted June 21, 2007 Author Share Posted June 21, 2007 I know but some things will be the same in priority. Should I just change it and use ENUM in the database? (I think it's ENUM ) Quote Link to comment https://forums.phpfreaks.com/topic/56582-wont-update-new-number/#findComment-279488 Share on other sites More sharing options...
Barand Posted June 21, 2007 Share Posted June 21, 2007 If you are going for equal priorities then if you now move 4 up it should also become 2, and not 3, as it should become the same priority as the one immediately above it. Quote Link to comment https://forums.phpfreaks.com/topic/56582-wont-update-new-number/#findComment-279492 Share on other sites More sharing options...
ryeman98 Posted June 21, 2007 Author Share Posted June 21, 2007 Ok. I just want it to work like this: The priority number is 3 and in the middle of the list. Then someone clicks on the up arrow and it moves up in priority to number 2. Then, if they click on the up arrow again, it goes to number 1 and is at the top of the list. I only want the number to change by one. Quote Link to comment https://forums.phpfreaks.com/topic/56582-wont-update-new-number/#findComment-279495 Share on other sites More sharing options...
Barand Posted June 21, 2007 Share Posted June 21, 2007 But in the case of D(4) if you only change it by one (to 3) you haven't increased it's priority - it still remains in 4th place behind A(1), B(2) and C(2) Quote Link to comment https://forums.phpfreaks.com/topic/56582-wont-update-new-number/#findComment-279499 Share on other sites More sharing options...
ryeman98 Posted June 21, 2007 Author Share Posted June 21, 2007 So how would I do that? Quote Link to comment https://forums.phpfreaks.com/topic/56582-wont-update-new-number/#findComment-279501 Share on other sites More sharing options...
Barand Posted June 21, 2007 Share Posted June 21, 2007 ... it should become the same priority as the one immediately above it. In this situation, A 1 B 2 C 2 D 4 E 5 Then D needs to become 2 also if moved up in priority SELECT MAX(priority) as newprority FROM projects WHERE priority < (SELECT priority FROM projects WHERE id = '$id') Then set the priority of D to the value of newpriority from that query Quote Link to comment https://forums.phpfreaks.com/topic/56582-wont-update-new-number/#findComment-279512 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.