Building Browsergames: Building Browsergames: Implementing a flexible stats system (PHP)
sHyuAn
· 5 months ago
"SELECT value FROM user_stats WHERE stat_id = (SELECT id FROM stats WHERE display_name = <foo> OR short_name = <foo>) AND user_id = <bar>"
when i put this into sql query, it shows me the error message as below:
"MySQL said:
#1064 - 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 '<foo> OR short_name = <foo>) AND user_id = <bar> LIMIT 0, 30' at line 1"
what should i do?
Luke
· 1 month ago
You need to actually put values into the <foo> and <bar> portions - if you read a little further, the code to do that is later on.
sHyuAn
· 5 months ago
"SELECT value FROM user_stats WHERE stat_id = (SELECT id FROM stats WHERE display_name = <foo> OR short_name = <foo>) AND user_id = <bar>"
i have inserted this into sql query.. however, the error message came out as below:
"MySQL said:
#1064 - 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 '<foo> OR short_name = <foo>) AND user_id = <bar> LIMIT 0, 30' at line 1"
what should I do now?
Luke
· 5 months ago
You're missing the string formatting that puts arguments into your SQL statement - add that, and you should be good to go.
Name
· 2 days ago
Don't use subqueries, where an inner join is more likely (and probably faster).
Change this:
SELECT value FROM user_stats WHERE stat_id = ( SELECT id FROM stats WHERE display_name = <foo> OR short_name = <foo>) AND user_id = <bar>
to this:
SELECT user_stats.value FROM user_stats INNER JOIN stats ON (user_stats.stat_id = stats.id) WHERE stats.display_name = <foo> AND stats.short_name = <foobar> AND user_stats.user_id = <bar>
when i put this into sql query, it shows me the error message as below:
"MySQL said:
#1064 - 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 '<foo> OR short_name = <foo>) AND user_id = <bar>
LIMIT 0, 30' at line 1"
what should i do?
i have inserted this into sql query.. however, the error message came out as below:
"MySQL said:
#1064 - 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 '<foo> OR short_name = <foo>) AND user_id = <bar>
LIMIT 0, 30' at line 1"
what should I do now?
statement - add that, and you should be good to go.
Change this:
SELECT value
FROM user_stats
WHERE stat_id = (
SELECT id
FROM stats
WHERE display_name = <foo> OR short_name = <foo>)
AND user_id = <bar>
to this:
SELECT user_stats.value
FROM user_stats
INNER JOIN stats
ON (user_stats.stat_id = stats.id)
WHERE stats.display_name = <foo> AND stats.short_name = <foobar> AND user_stats.user_id = <bar>