清除票数大于50的PHP脚本

时间:2015-06-16 19:59:29

标签: php mysql

我只想重置大于50的投票,目前重置每一个

    <?
include('mysql_connect.php');
$query = "SELECT id, votes, callback FROM websites";
$result = mysql_query($query) OR die(mysql_error());
$query = "UPDATE websites SET votes = 0";
$result = mysql_query($query) OR die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);


echo ('Database has been cleaned with a tissue.');
?>

我习惯编码Java所以我不确定我是否可以使用这个

$query = "UPDATE websites WHERE votes >= 50 SET votes = 0";

感谢您的帮助

2 个答案:

答案 0 :(得分:3)

你关闭了。这样做。

$query = "UPDATE websites SET votes = 0 WHERE votes >= 50 ";

自PHP 5.5.0起,不再使用mysql_*函数,将来也会删除它们。相反,应使用MySQLiPDO_MySQL扩展名。

答案 1 :(得分:2)

您需要SET:

之后的WHERE语句
$query = "UPDATE websites SET votes = 0 WHERE votes >= 50";