简体   繁体   中英

Select Next Row Needed In Query

So I have an attack system on my game where players use weapons they have purchased and can attack each other. Well they also have friends who they fight with and you level up in the game. For each level you can fight with 5 more people so it's like this: Level * 5 = Mob Available For example: I'm level 5 and have 100 Friends; I can fight with 25 of those friends and use 25 weapons in each category. here's a ScreenShot So Say in the Melee Category, I have 10 Knives, 5 Baseball Bats, And 10 Axes. How would I set it up to use the best attack Weapons? Here's the code I'm using now to limit and select 1 weapon at the moment:

if($level >= 100) {
if($mob_size >=500) {
$a_melee_avail = 500 + $hired_guns; 
}
else {  
$a_melee_avail = $total_mob;    
    }
}
if($level < 100) {
if($mob_size > $level * 5) {    
$a_melee_avail = $level * 5; 
}
else {
$a_melee_avail = $mob_size; 
    }
}
$check_a_melee = mysql_query("SELECT * FROM weapons WHERE owner_id=".$id." AND type='melee' AND owned>=".$a_melee_avail." LIMIT 1");
$check_a_mel_info = mysql_fetch_array($check_a_melee);
$a_mel_limit_plus1 = ($check_a_mel_info['id'] + 1);
// Checking melee owned
if(mysql_num_rows($check_a_melee) == 0) {
$a_get_melee = mysql_query("SELECT * FROM weapons WHERE owner_id=".$id." AND type='melee' AND owned<=".$a_melee_avail." ORDER BY attack DESC LIMIT 1"); 
}
if(mysql_num_rows($check_a_melee) == 1) {
$a_get_melee = mysql_query("SELECT * FROM weapons WHERE owner_id=".$id." AND type='melee' AND owned>=".$a_melee_avail." ORDER BY attack DESC LIMIT 1");     
}
$a_melee = mysql_fetch_array($a_get_melee);
$a_melee_name = $a_melee['name'];
$a_melee_attack = $a_melee['attack'];
$a_melee_owned = $a_melee['owned'];
// Checking Availability
if($a_melee_owned >= $a_melee_avail) {
$a_melee_used = $a_melee_avail; 
}
if($a_melee_owned < $a_melee_avail) {
$a_melee_used = $a_melee_owned; 
}
$a_melee_damage = $a_melee_attack * $a_melee_used;

But that just select 1 of the best weapons based on attack, How could I set it to where they use all available weapons?

Could you use sortfeild

function __construct($sortField) { $this->sortField = $sortField; }

public function compare($a, $b)
{
  return strnatcmp($b[$this->sortField], $a[$this->sortField]);
}

}

And the your array could be used in a list right?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM