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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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. 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.