order priority when making an update.

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
motecl
New php-forum User
New php-forum User
Posts: 1
Joined: Thu Sep 06, 2018 9:36 am

Thu Sep 06, 2018 9:46 am

Hello, I have a doubt. I'm doing an app and in is schedule for works. I get the list sorted by the column priority.

Code: Select all

 ----------------------
|priority |activity   |
|---------|-----------|
|   1     |act1       |
|   2     |act2       |
|   3     |act3       |
|---------|-----------|
here my JSON file where I do the update
I add method but it does not work like I want

Code: Select all

 <?php
    //update.php
    include_once('../include/conexion.php');

    $query = "
     UPDATE ACT_schedule SET ".$_POST["name"]." = '".$_POST["value"]."'
     WHERE id_schedule = '".$_POST["pk"]."'";

    $result=mysqli_query($conn, $query);
    if ($result) {
    //method for order priority
    $query2 = "UPDATE ACT_Agenda SET prioridad = CASE 
           WHEN prioridad >= " . $_POST['value'] . "
           THEN prioridad + 1 ELSE prioridad - 1 END
           WHERE id_agenda <> '" . $_POST['pk'] . "'";
    mysqli_query($conn, $query2);
    echo "YES";
}
    ?>
My question is if I can REORDER the priority, example, the act2 that has priority 2 if I modify it to 1 it changes to 1 but the act1 that had priority 1 changes to priority 2. I hope I have explained well any info I will be very grateful

An example of how I would have the table and the view.

Code: Select all

  ----------------------
    |prioridad|actividad  |
    |---------|-----------|
    |   1     |act2       |
    |   2     |act1       |
    |   3     |act3       |
    |---------|-----------|

Post Reply