cdoyle Posted March 11, 2008 Share Posted March 11, 2008 Hi, I'm having a hard time pulling in the data that I want to display on my page. Here is what I'm trying to do. I have a table named players It has a field named 'kills' (keeps total number of kills a player has) I have a battle_rank table Minimum_Wins (minimum number of kills needed to get this rank) Rank_Description (description of this rank) examples rows from rank description ID Minumum_Wins Icon_Path Rank_Description 1 150 images/smilies/killer.gif Hitman 3 1 images/smilies/noob.gif NOOB!!! 4 200 images/smilies/ninja.gif Ninja What I need to do is create a query that will display the current rank of the player. If a player has less then 150 kills he gets a 'noob' ranking If a player has 150 or more he gets 'hitman' If a player has 200 or more he gets 'ninja' and it will keep going as I update the table. I just can't seem to get the query to pull only the data I need. I've been experimenting and the best I came up with, was this. <?php $queryrank = $db->Execute("select * from `battle_rank` where '$player->kills'>=`Minimum_Wins`"); $battlerank = $queryrank->fetchrow(); echo $battlerank['Rank_Description'] . "\n<br />"; ?> but it doesn't work. I'm hoping someone with more experience writing queries can see where I'm going wrong! I know one thing I'm missing it to make sure it displays only the highest description the player has. So if he has 200 kills it doesn't retrieve both hitman and ninja rows. It needs to pull just the ninja row. Any suggestions? Quote Link to comment Share on other sites More sharing options...
l0ve2hat3 Posted March 11, 2008 Share Posted March 11, 2008 maybe try this: $sql = "SELECT * FROM`battle_rank` WHERE `Minimum_Wins`>='$player->kills' AND `Minimum_Wins`<='$player->kills' " Quote Link to comment Share on other sites More sharing options...
cdoyle Posted March 11, 2008 Author Share Posted March 11, 2008 maybe try this: $sql = "SELECT * FROM`battle_rank` WHERE `Minimum_Wins`>='$player->kills' AND `Minimum_Wins`<='$player->kills' " Thanks, but it didn't work. I have my test player set to 46 wins, and that should give cause the 'noob' rating to appear, but it doesn't. Quote Link to comment Share on other sites More sharing options...
trq Posted March 11, 2008 Share Posted March 11, 2008 I'm not sure this is your issue but complex variables should be wrapped within curly braces when being interpolated into a string. $sql = "SELECT * FROM`battle_rank` WHERE `Minimum_Wins`>='{$player->kills}' AND `Minimum_Wins`<='{$player->kills}'" If that query fails, try printing $sql to see what your query actually looks like. Quote Link to comment Share on other sites More sharing options...
cdoyle Posted March 11, 2008 Author Share Posted March 11, 2008 I'm not sure this is your issue but complex variables should be wrapped within curly braces when being interpolated into a string. $sql = "SELECT * FROM`battle_rank` WHERE `Minimum_Wins`>='{$player->kills}' AND `Minimum_Wins`<='{$player->kills}'" If that query fails, try printing $sql to see what your query actually looks like. How do I print $sql? Since the code above seems to not be adodb, should the code on my page looks like this now? $sql = "SELECT * FROM`battle_rank` WHERE `Minimum_Wins`>='{$player->kills}' AND `Minimum_Wins`<='{$player->kills}'" $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)){ echo $row['Rank_Description'].'<br />'; } If so, I now get this error,when I display the page Parse error: syntax error, unexpected T_VARIABLE in /home/caraudi/public_html/CAC_Mafia_Life/TMPn6cnrxl7n4.php on line 99 Quote Link to comment Share on other sites More sharing options...
l0ve2hat3 Posted March 11, 2008 Share Posted March 11, 2008 $sql = "SELECT * FROM`battle_rank` WHERE `Minimum_Wins`>='{$player->kills}' AND `Minimum_Wins`<='{$player->kills}'" your missing the ";" at the end!! Quote Link to comment Share on other sites More sharing options...
cdoyle Posted March 11, 2008 Author Share Posted March 11, 2008 oh geeze, that took care of the error, but still nothing displays on the page. How do I print $sql? I can do that and print the results here. Quote Link to comment Share on other sites More sharing options...
cdoyle Posted March 11, 2008 Author Share Posted March 11, 2008 Not sure if this helps at all, but... I have a VB board, and one of the things it does is gives users a different user title, once they reach a certain post amount. $gettitle = $DB_site->query_first("SELECT title FROM " . TABLE_PREFIX . "usertitle WHERE minposts<=$bbuserinfo[posts] ORDER BY minposts DESC LIMIT 1"); $customtext = $gettitle['title']; This function is basically the same thing I'm trying to do with the kill amounts. 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.