index.php
/**
 * Perform the up action.
 *
 * @param $sql_conn \mysqli The mysqli connection
 */
Perform the up action.
@param $sql_conn \mysqli The mysqli connection
Perform the up action . @param $sql_conn \ mysqli The mysqli connection
function act_up($sql_conn)
{
    $pid = $_POST["pid"];
    $result = $sql_conn->query("SELECT `follows` FROM `problem` WHERE `pid` = $pid;");
    if (!$result) {
        die("move up failed: get target follows");
    }
    $follows = $result->fetch_assoc()["follows"];
    $result = $sql_conn->query("SELECT `pid` FROM `problem` WHERE `follows` = $pid;");
    if (!$result) {
        die("move up failed: get target follower");
    }
    $follower = $result->fetch_assoc()["pid"];
    if ($follows == 0)
        return;
    $result = $sql_conn->query("UPDATE `problem` SET `follows` = (SELECT `follows` FROM (SELECT * FROM `problem`) AS temp WHERE `pid` = $follows) WHERE `pid` = $pid;");
    if (!$result) {
        die("move up failed: exclude preceding: $sql_conn->error");
    }
    $result = $sql_conn->query("UPDATE `problem` SET `follows` = $pid WHERE `pid` = $follows;");
    if (!$result) {
        die("move up failed: reroute preceding: $sql_conn->error");
    }
    if (!$follower)
        return;
    $result = $sql_conn->query("UPDATE `problem` SET `follows` = $follows WHERE `pid` = $follower;");
    if (!$result) {
        die("move up failed: reroute follower: $sql_conn->error");
    }
}
function act_up ( $ sql_conn ) { $ pid = $ _POST [ " pid " ] ; $ result = $ sql_conn -> query ( " SELECT `follows` FROM `problem` WHERE `pid` =  $ pid ; " ) ; if ( ! $ result ) { die ( " move up failed: get target follows " ) ; } $ follows = $ result -> fetch_assoc ( ) [ " follows " ] ; $ result = $ sql_conn -> query ( " SELECT `pid` FROM `problem` WHERE `follows` =  $ pid ; " ) ; if ( ! $ result ) { die ( " move up failed: get target follower " ) ; } $ follower = $ result -> fetch_assoc ( ) [ " pid " ] ; if ( $ follows == 0 ) return ; $ result = $ sql_conn -> query ( " UPDATE `problem` SET `follows` = (SELECT `follows` FROM (SELECT * FROM `problem`) AS temp WHERE `pid` =  $ follows ) WHERE `pid` =  $ pid ; " ) ; if ( ! $ result ) { die ( " move up failed: exclude preceding:  $ sql_conn -> error " ) ; } $ result = $ sql_conn -> query ( " UPDATE `problem` SET `follows` =  $ pid  WHERE `pid` =  $ follows ; " ) ; if ( ! $ result ) { die ( " move up failed: reroute preceding:  $ sql_conn -> error " ) ; } if ( ! $ follower ) return ; $ result = $ sql_conn -> query ( " UPDATE `problem` SET `follows` =  $ follows  WHERE `pid` =  $ follower ; " ) ; if ( ! $ result ) { die ( " move up failed: reroute follower:  $ sql_conn -> error " ) ; } }
Perform the up action.
Perform the up action .
// Get action parameters // Get target problem's follows // Get target problem's follower // Stop if target problem is already first // Make target follow target follows' follows // Make target follows follow target // Stop if problem is last // Make target follower follow target follows