1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
$posnow = $valeuractuelle;
$posnew = $_POST['position'];
$posadd = $posnow + 1;
$posless = $posnow - 1;
if($_SERVER['REQUEST_METHOD'] == "POST")
{
if ($posnow == $posnew) //si on ne change rien
{
echo "rien n'a changé !";
}
elseif (($posnow == "0") AND ($posnew != '0')) //si on ajoute un membre à l'affichage
{
echo "on ajoute un membre dans l'affichage";
$maj1 = "UPDATE matable SET position = position + 1 WHERE position >= '$posnew' ";
$req_maj1 = mysqli_query($maconnexion, $maj1) or die($maj1. mysqli_error());
$maj2 = "UPDATE matable SET position = '$posnew' WHERE id = '$idmembre'";
$req_maj2 = mysqli_query($maconnexion, $maj2) or die($maj2. mysqli_error());
}
elseif ($posnew == "0") //si on retire un membre de l'affichage
{
echo "Le membre a bien été retiré de la liste d'affichage";
$maj1 = "UPDATE matable SET position = position - 1 WHERE position >= '$posnow' ";
$req_maj1 = mysqli_query($maconnexion, $maj1) or die($maj1. mysqli_error());
$maj2 = "UPDATE matable SET position = '$posnew' WHERE id = '$idmembre'";
$req_maj2 = mysqli_query($maconnexion, $maj2) or die($maj2. mysqli_error());
}
elseif (($posnow != "0") AND ($posnew > $posnow)) //si on envoie le membre vers la fin de la liste
{
echo "Le membre est bien déplacé vers la fin de la liste";
$maj1 = "UPDATE matable SET position = position - 1 WHERE position BETWEEN '$posadd' AND '$posnew' ";
$req_maj1 = mysqli_query($maconnexion, $maj1) or die($maj1. mysqli_error());
$maj2 = "UPDATE matable SET position = '$posnew' WHERE id = '$idmembre'";
$req_maj2 = mysqli_query($maconnexion, $maj2) or die($maj2. mysqli_error());
}
elseif (($posnew < $posnow) AND ($posnew != "0")) //si on envoie le membre vers le début de la liste
{
echo "Le membre est bien déplacé vers le début de la liste";
$maj1 = "UPDATE matable SET position = position + 1 WHERE position BETWEEN '$posnew' AND '$posless' ";
$req_maj1 = mysqli_query($maconnexion, $maj1) or die($maj1. mysqli_error());
$maj2 = "UPDATE matable SET position = '$posnew' WHERE id = '$idmembre'";
$req_maj2 = mysqli_query($maconnexion, $maj2) or die($maj2. mysqli_error());
}
else
{
echo "choix par défaut";
}
} |
Partager