DeanWhitehouse Posted December 22, 2008 Share Posted December 22, 2008 My function returns blank <?php function get_rank($exp) { $sql = "SELECT * FROM rank WHERE start >= '".$exp."' AND end <= '".$exp."'"; $sql = mysql_query($sql); $sql = mysql_fetch_assoc($sql); return $sql['rank']; } ?> And when debugged found out that the query is returning zero rows. But the $exp is 0 and in the database it looks like id rank start end 1 Rank 1 0 100 Quote Link to comment https://forums.phpfreaks.com/topic/138072-solved-sql-statement/ Share on other sites More sharing options...
ngreenwood6 Posted December 22, 2008 Share Posted December 22, 2008 so you have a table and a field named rank? Quote Link to comment https://forums.phpfreaks.com/topic/138072-solved-sql-statement/#findComment-721728 Share on other sites More sharing options...
DeanWhitehouse Posted December 22, 2008 Author Share Posted December 22, 2008 obviously And when debugged found out that the query is returning zero rows If not that would of produced an error Quote Link to comment https://forums.phpfreaks.com/topic/138072-solved-sql-statement/#findComment-721730 Share on other sites More sharing options...
premiso Posted December 22, 2008 Share Posted December 22, 2008 Try running that query in PHPMyAdmin and see what happens. Also try running SELECT * FROM rank where start >= 0 And see what is returned and do the same with just end. Also try removing the single quotes (') and see if that helps at all. Quote Link to comment https://forums.phpfreaks.com/topic/138072-solved-sql-statement/#findComment-721734 Share on other sites More sharing options...
ngreenwood6 Posted December 22, 2008 Share Posted December 22, 2008 I was just asking a simple question to make sure that you did not try to pull the wrong data. happens to the best of us. If $exp is 0 then it isn't going to return anything because end <= '".$exp."' $exp = 0 end = 100 100 is not less than or equal to 0. Quote Link to comment https://forums.phpfreaks.com/topic/138072-solved-sql-statement/#findComment-721736 Share on other sites More sharing options...
DeanWhitehouse Posted December 22, 2008 Author Share Posted December 22, 2008 Just realised why AND end <= '".$exp."' It is not less than or equal to 0, but is required for other ranks Now :s Any ideas? Edit: beat me to it :S Quote Link to comment https://forums.phpfreaks.com/topic/138072-solved-sql-statement/#findComment-721738 Share on other sites More sharing options...
DarkerAngel Posted December 22, 2008 Share Posted December 22, 2008 its going to always produce no results the way your doing it Start = 0 0 >= 0: true End = 100 100 <= 0: false 0 results! Quote Link to comment https://forums.phpfreaks.com/topic/138072-solved-sql-statement/#findComment-721742 Share on other sites More sharing options...
revraz Posted December 22, 2008 Share Posted December 22, 2008 Use two variables? Quote Link to comment https://forums.phpfreaks.com/topic/138072-solved-sql-statement/#findComment-721743 Share on other sites More sharing options...
DeanWhitehouse Posted December 22, 2008 Author Share Posted December 22, 2008 Use two variables? As? Quote Link to comment https://forums.phpfreaks.com/topic/138072-solved-sql-statement/#findComment-721744 Share on other sites More sharing options...
premiso Posted December 22, 2008 Share Posted December 22, 2008 function get_rank($sExp, $eExp) Like that, pass in the start and the end. Quote Link to comment https://forums.phpfreaks.com/topic/138072-solved-sql-statement/#findComment-721746 Share on other sites More sharing options...
revraz Posted December 22, 2008 Share Posted December 22, 2008 If you are looking to get just 1 rank, then do your WHERE based on just 1 rank. If you are looking for a Range, then provide the range. Quote Link to comment https://forums.phpfreaks.com/topic/138072-solved-sql-statement/#findComment-721748 Share on other sites More sharing options...
DarkerAngel Posted December 22, 2008 Share Posted December 22, 2008 $sql = "SELECT * FROM rank WHERE '".$exp."' BETWEEN start AND end"; Would that work? I dont know... lol I'm lost to exactly what your trying to do... Quote Link to comment https://forums.phpfreaks.com/topic/138072-solved-sql-statement/#findComment-721750 Share on other sites More sharing options...
DeanWhitehouse Posted December 22, 2008 Author Share Posted December 22, 2008 I know how to @premiso i was asking what they would be @revraz our rank table is id rank start end 1 Rank 1 0 100 2 Rank 2 100 200 3 Rank 3 200 300 4 Rank 4 300 400 And what the user has is experience, e.g. user1 has 0 exp (he has just joined) but user2 has 150 exp @DarkerAngel, i think that has done it Quote Link to comment https://forums.phpfreaks.com/topic/138072-solved-sql-statement/#findComment-721751 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.