MySQL SET @ not working in PHP mysql_query()
Posted: Mon Oct 11, 2010 8:02 pm
I have a perfectly working MySQL query written below. But when I place it in the mysql_query() fucntion to query the data, I receive the following error. If I remove the SET command then all works fine. Any ideas what I can do to use the SET function in mysql_query() without breaking it? Thanks!
Query:
SET @rank=0;
SELECT rank FROM (
SELECT @rank:=@rank+1 AS rank, value, name, parent_id
FROM core_actionfield
where name = 'pacman_score'
ORDER BY CAST(value as Signed) DESC
) as result
WHERE parent_id = 123456 ";
Error when I place it in mysql_query():
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 'SELECT rank FROM (SELECT @rank:=@rank+1 AS rank, value, name, parent_id FROM cor' at line 1
Query:
SET @rank=0;
SELECT rank FROM (
SELECT @rank:=@rank+1 AS rank, value, name, parent_id
FROM core_actionfield
where name = 'pacman_score'
ORDER BY CAST(value as Signed) DESC
) as result
WHERE parent_id = 123456 ";
Error when I place it in mysql_query():
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 'SELECT rank FROM (SELECT @rank:=@rank+1 AS rank, value, name, parent_id FROM cor' at line 1