• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sub request in where

#1
Hello,
I come to you because I need help on request ...

I have a rank table that lists all the ranks available to a player with the maximum number of points for the rank.
I have another table users who list my players with their experience.

I want to use the experience of players to display the rank corresponding to the experience.

Example :

[b]rank table[/b]
|    id    |    grade    |    point    |
__________________________
|    1    |   Niveau 1  |     300    |
|    2    |   Niveau 2  |     600    |

users table
|    id    |    name    |    experience    |
______________________________
|    1    |      test      |     330             |


So if my player has an experience of 330 I need to display a level of 2 because above 300 and below 600.

PHP Code:
/*
// This works if I enter the experience value directly
$this->db->select('*')
            ->from('rank')
            ->where('point >=', 1200);
*/

// This not work I can't arrive to get the experience user
$this->db->select('*')
            ->
from('rank')
            ->
where('point >='"SELECT 'experience' FROM 'users' WHERE 'name' =  $username");


$query $this->db->get();

if(
$query->num_rows()>0)
{
    return 
$query->row_array();

Reply

#2
@xenos92,

Will the rank table always be dynamic or are there set from and to values for each level? Is this a MySQL database?
Reply

#3
how about
Code:
function rankedplayers()
 ranks = this->db->query(select * from ranks table order by point asc);
 players = this->db->query(select * from players order by name);
 foreach players as player
   prior = 'invalid';
   foreach ranks as rank
if (player->points < rank->point){
prior = rank->grade;
break;
}
}
player->rank = prior;
 }
 return players;
}
Reply

#4
Thank you badger Wink
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.