Jump to content

Won't update new number...


ryeman98

Recommended Posts

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

Link to comment
Share on other sites

[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]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

... 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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.