It's work with PHP variables:
Prepearing one result from query function
extract($GLOBALS);
$GLOBALS['mysqli'] = $mysqli;
function select($a,$b){
$mysqli = $GLOBALS['mysqli'];
$query = $mysqli -> query($b);
while($row = ($query -> fetch_assoc())){
return $row[$a]."<br>";
}// while
$query -> free();
}
order from where clicked
$self = "SELECT order FROM channels WHERE id='$id'";
$self = "(SELECT order FROM (($self)AS x))";
if($btn == "Up"){
// Order previows
$other = "SELECT MAX(order) FROM channels WHERE order < $self";
}
if($btn == "Down"){
// Order next
$other = "SELECT MIN(order) FROM channels WHERE order > $self";
}
$other = "SELECT order FROM channels WHERE order=($other)";
SET PHP VARIABLE INSTEAD OF MYSQL VARIABLE $other = select('order',$other);
$query = "UPDATE channels SET order=$self WHERE order='$other';";
$query .= "UPDATE channels SET order='$other' WHERE id='$id'";
$mysqli->multi_query($query);
The problem? I need a faster query using one MySQL query
This doesnt' work:
SET MYSQL VARIABLE INSTEAD O PHP VARIABLE
$query = "DEFINE other INT;"; // return: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DEFINE other INT(...);
$query .= "DECLARE other INT;"; // return: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE other INT(...);
$query .= "SET other = $other;"; // return: Unknown system variable 'other'
$query .= "UPDATE channels SET order=$self WHERE order=other;";
$query .= "UPDATE channels SET order=other WHERE id='$id'";
$mysqli->multi_query($query);