Jump to content

Need help writing adobd query


cdoyle

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/95546-need-help-writing-adobd-query/
Share on other sites

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.

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.

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

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. 

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.