Mysql Variables not working through php mysql query -
i have query:
$query = " set @points := -1; set @num := 0; select `id`,`rank`, @num := if(@points = `rank`, @num, @num + 1) `point_rank` `said` order `rank` *1 desc, `id` asc";
i'm using query php; giving me error:
you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'set @num := 0;
if copy , paste code in phpmyadmin sql query panel, works perfectly, php code lines it's not working, seems there's issues while setting vars.
instead of setting variables in separate set
, have tried using cross join
:
$query = " select `id`, `rank`, @num := if(@points = `rank`, @num, @num + 1) `point_rank` `said` cross join (select @points:=-1, @num:=0) c order `rank` *1 desc, `id` asc";
Comments
Post a Comment