[英]How to sort rows in MySQL database
I have this code 我有这个代码
$link = new mysqli('localhost', 'root', '', 'domaci2');
$query = 'SELECT * FROM utisci';
$result = $link->query($query);
while ($row=$result->fetch_assoc()){
$link->query('SELECT pk FROM utisci ORDER BY ocena DESC');
}
$result->free();
mysqli_close($link);
It is very simple, i am just trying to sort my table but it is not working. 这很简单,我只是想对我的表进行排序,但是它不起作用。
Extra info: 额外信息:
Don't do SELECT pk FROM utisci ORDER BY ocena DESC
in the body of the while
loop. 不要在
while
循环的主体中通过SELECT pk FROM utisci ORDER BY ocena DESC
执行SELECT pk FROM utisci ORDER BY ocena DESC
。 Do it before the while
loop instead of SELECT * FROM utisci
. 在
while
循环之前执行此操作, while
不要执行SELECT * FROM utisci
。
This should work 这应该工作
$link = new mysqli('localhost', 'root', '', 'domaci2');
$query = 'SELECT pk FROM utisci ORDER BY ocena DESC';
$result = $link->query($query);
while ($row=$result->fetch_assoc()){
// what you want to do with $row
}
$result->free();
mysqli_close($link);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.