我得到了一个积分系统,就像人们可以升级到[PRO1]用户一样。每个人的权限(pro1,pro2,用户)存储在我的mysql用户表中。但是我想作一点提要,以显示最新的提要升级到[PRO1]的提要。升级代码:
$insert = "UPDATE `users` SET `points` = (`points`-50) WHERE `username` = '".$username."' and points > 50";
mysql_query($insert);
if (mysql_affected_rows() > 0)
{
// other codes
$insert = "UPDATE users SET rights=' [PRO1]' WHERE `username` = '".$username."'";
mysql_query($insert);
header('location: succesupgrade.php');
}else{
echo "You don't have enough points";
}
?>
升级代码可以正常工作(以防万一我需要添加时间/日期。此代码中我希望“用户名”不是最后一次升级到[PRO1]的代码):
<?php
require("dbc.php");
$query = mysql_query("select * from users WHERE rights='[PRO1]' order by right DESC limit 1") or die(mysql_error());
while($array = mysql_fetch_array($query)) {
echo "{$array['username']}<br>";
}
?>was the last to upgrade to:
<?php
require("dbc.php");
$query = mysql_query("select * from users WHERE rights='[PRO1]' order by rights DESC limit 1") or die(mysql_error());
while($array = mysql_fetch_array($query)) {
echo "{$array['rights']}<br>";
}
?>
但是该代码给了我这个错误:
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 'DESC limit 1' at line 1
最佳答案
在第二个代码块的第一个查询中,order by right
必须为order by rights
。