使用MySQLi设置MySQL变量(不是PHP变量) [英] Set MySQL Variables with MySQLi (not PHP variables)
本文介绍了使用MySQLi设置MySQL变量(不是PHP变量)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它适用于PHP变量:
通过查询功能替代一个结果
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();
}
点击位置的顺序
$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)";
设置PHP变量代替MYSQL变量 $ other = select('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);
有问题吗?我需要使用一个MySQL查询进行快速查询
这不起作用:
The problem? I need a faster query using one MySQL query
This doesnt' work:
设置MYSQL变量代替PHP变量
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);
推荐答案
查看全文