Damond Posted December 13, 2014 Share Posted December 13, 2014 (edited) Hello everyone, So I'm fairly new to the PHP and MySQL scene and I know it is just something simple that I am over looking. I am using a version of streets that allows you to attack the NPCs for experience. We have a rank system and want our players to be able to attack only the NPC of equal rank. Here is my query: else if($step['reward_type'] == 'npc'){ $q=$db->query("SELECT cb.*,u.* FROM challengebots cb LEFT JOIN users u ON cb.cb_npcid=u.userid LEFT JOIN cities cy ON u.location=cy.cityid WHERE u.level <= {$ir['level']} LIMIT 1"); $s=$db->fetch_row($q); print"While out prowling you run into {$s['username']}, they seem to be looking for a fight.<br /> <a href='npc_attack.php?ID={$s['userid']}'>Fight them?</a><br/>"; } For some reason it is always giving you the lowest level NPC not the one closest to your level without going over your level. I added a second attack page called npc_attack.php so that I could take out the location restriction and you could fight any NPC for any town while in your streets. As I said I know it is something simple that I am just over looking, but again I'm really new to using PHP and MySQL. Thanks for any help. Edited December 13, 2014 by KyleMassacre Added code tags And fixed formatting Quote Link to comment Share on other sites More sharing options...
Coly010 Posted December 13, 2014 Share Posted December 13, 2014 Your sql query appears wrong. Your joining only the npc which had the same id as the user who is searching the street, try using ON cb.cb_level = u.level WHERE u.userid ='$userid' Quote Link to comment Share on other sites More sharing options...
Veramys Posted December 13, 2014 Share Posted December 13, 2014 [MENTION=65530]Coly010[/MENTION] Firstly no that's not right. One cb_level doesn't exist in the challengebots table, two he wants it to select closest to the users level but not above so if you have a bot that is level 100 and you're level 110 and the next bot above is level 150 then it selects the level 100 bot and not above or say the level 1 bot. Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted December 13, 2014 Share Posted December 13, 2014 Can you please use the code or php tags when you post code? It's makes it easy for us to read. Also, can you give us some stats of "your" level and the level of the NPC it should be selecting? Is there a NPC that would meet that criteria? Example: Say you are level 20 and the lowest level NPC is 10 and the next level is 25, your query should run and give you the level 10 bot, is that a similar case that you have? Quote Link to comment Share on other sites More sharing options...
Damond Posted December 13, 2014 Author Share Posted December 13, 2014 Sorry about the code tags I'm new to a forum like this and trying to pick up on all the rules as quickly as I can. I will do my best to remember the code tags next time. So my user level is level 90. There is a bot at level 75 and then the next is at level 101. I should be calling to the level 75 bot until I reach level 101, but right now it is calling to the lowest level bot, that being the level 1 bot of course. Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted December 13, 2014 Share Posted December 13, 2014 Try adding this to your SQL: order by u.level desc Quote Link to comment Share on other sites More sharing options...
Damond Posted December 13, 2014 Author Share Posted December 13, 2014 That worked perfectly. Thank you so much. Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted December 13, 2014 Share Posted December 13, 2014 Not a problem Quote Link to comment Share on other sites More sharing options...
Coly010 Posted December 13, 2014 Share Posted December 13, 2014 [MENTION=65530]Coly010[/MENTION] Firstly no that's not right. One cb_level doesn't exist in the challengebots table, two he wants it to select closest to the users level but not above so if you have a bot that is level 100 and you're level 110 and the next bot above is level 150 then it selects the level 100 bot and not above or say the level 1 bot. I have never seen the table, so I was assuming what there would be. However i should have stated that what I had posted wasn't an actual fix, but something to think about. Quote Link to comment Share on other sites More sharing options...
Veramys Posted December 13, 2014 Share Posted December 13, 2014 Sorry if I was rude earlier. I was a bit cranky. Quote Link to comment 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.