sooty2006 Posted July 22, 2010 Share Posted July 22, 2010 Hi, In my database table i have 50 rows, every time the user levels up they unlock a new crime.i want to show the new crimes by the top ten crimes my code just brings the last 10 in the database even tho they have not unlocked it!can anyone show me how to get it to do this?here is my current code! $sql = "SELECT * FROM `crimes` WHERE `crime_count` <= '$array[crime_total]' ORDER BY id DESC LIMIT 10";$query = mysql_query($sql);while($row = mysql_fetch_array($query)){ Thanks Link to comment Share on other sites More sharing options...
thescientist Posted July 22, 2010 Share Posted July 22, 2010 you would probably want to add something that checks the level of crimes they have access to, and then make that the limit. So if they've only gotten up to level 5 or something, then the LIMIT would be 5 instead. Link to comment Share on other sites More sharing options...
sooty2006 Posted July 22, 2010 Author Share Posted July 22, 2010 ok i understand what your saying but if the user is on level 15 i only want it to show the last 10 crimes unlocked not the first 5 Link to comment Share on other sites More sharing options...
thescientist Posted July 22, 2010 Share Posted July 22, 2010 ok, well think a little creatively then. if they've achieved a level higher than 10, then only show the last 10. If they are level 10 or under, then show their current levels worth of crimes, which would <= 10. Basically an if/else statement predicated on their level, which you can then set to a $limit variable which you can use in your query. Link to comment Share on other sites More sharing options...
sooty2006 Posted July 22, 2010 Author Share Posted July 22, 2010 ok ill give it ago then ! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.