尝试检查时出错 [英] Error while trying to check
问题描述
我想检查一些事情......但我不能......(检查下面).
i wanna do check for few things.... but i'm not able to...(check below).
好的,所以它是如何工作的,但我想再添加一张支票.
Okey so this works how it is but i wanna add more one check.
mysql_query('UPDATE characters SET voted=1 where account_name like \''.$row['login'].'\' and online=1;') ;
无论如何我要添加的是在 online=1 之后检查在哪里MIN(lastAccess)
Anyway what i wanna add is after online=1 to check
where
MIN(lastAccess)
我尝试了几件事,但我失败了...喜欢:
I tried few things but i failed... like:
mysql_query('UPDATE characters SET voted=1 where account_name like \''.$row['login'].'\' and online=1 having min(lastaccess);') ;
推荐答案
您甚至可以根据需要进一步加入表格,
You can even further join the tables to work as desired,
UPDATE characters a
INNER JOIN
(
SELECT account_name, MIN(lastaccess) min_date
FROM characters
GROUP BY account_name
) b ON a.Account_Name = b.Account_name AND
a.lastAccess = b.min_date
SET a.voted = 1
WHERE a.Account_Name = 'nameHere' AND
a.online = 1
更新 1
尝试使用双引号
,例如
$userName = $row['login'];
$result = mysql_query(" UPDATE characters a
INNER JOIN
(
SELECT account_name, MIN(lastaccess) min_date
FROM characters
GROUP BY account_name
) b ON a.Account_Name = b.Account_name AND
a.lastAccess = b.min_date
SET a.voted = 1
WHERE a.Account_Name = '$userName' AND
a.online = 1");
作为旁注,查询容易受到SQL注入
的影响,如果变量的 value(s) 来自外部.请查看下面的文章,了解如何预防.通过使用 PreparedStatements
,您可以摆脱在值周围使用单引号.
As a sidenote, the query is vulnerable with SQL Injection
if the value(s) of the variables came from the outside. Please take a look at the article below to learn how to prevent from it. By using PreparedStatements
you can get rid of using single quotes around values.
这篇关于尝试检查时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!