Click here to Skip to main content
16,018,234 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am finding problem in get correct result from query that I have written.
Below is my mysql query to get the levelId,levelRange,16,NextRange from database

SQL
"select levelId,levelRange,16 as totalSave,
(		
  case @i:=(level+1) 
	when @i then (select levelRange from level where levelId=@i;)					
  End
) As  NextRange
from level where levelRange <= 16 order by levelId desc limit 1"

I have used this query in PHP.
But it always gives me result as 0,0,16,NULL respectively for respective select items.

database table "level" is as follow,

XML
levelId| levelRange
   1   |    5
   2   |    10
   3   |    15
   4   |    20
   5   |    25

Here, the value "16" decides the next range value. So expected result should be "3,15,16,20"
where "levelId=3,levelRange=15,totalSave=16,NextRange=20".

Is their any way to get this result. I am using @i as to make it dynamic. So that no change will be required from coding side if in future levelId and levelRange changes from database
Posted
Updated 9-Jul-13 20:00pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900