MYSQL查询大于AND小于

时间:2019-08-07 23:33:18

标签: php mysql

我有一个名为character_level的表:

level                  experience
  1                         0
  2                         998
  3                         2994
  4                         5988

以此类推。

我还有另一个表user_Character¨

ID                   character_current_xp
1                          150
2                           35

要检查是否必须更改级别,请执行以下操作:

$xp = mysqli_query($con,"SELECT character_current_xp FROM user_character WHERE ID = '$currentUser'");
while($row = mysqli_fetch_array($xp))
  {
        $current_xp = $row['character_current_xp'];
  }
$lvl2 = mysqli_query($con,"SELECT level FROM character_level WHERE experience <= $current_xp order by experience desc limit 1");
while($row = mysqli_fetch_array($lvl2))
  {
  $level_after = $row['level'];
  }



if(isset($_POST['accept_xp'])){ //with this i check ressults
        $setxp = "UPDATE user_character SET character_current_xp = character_current_xp+100, character_current_lvl = $level_after  WHERE ID = $currentUser"; 

        mysqli_query($con, $setxp);
        mysqli_close($con);
        header('Location: account.php');
    }

问题是我使用<= $current_xp order by experience desc limit 1还是>= $current_xp order by experience desc仍然没有达到一个水平。

任何人都可以射击我什么? 提前致谢。 克里斯

1 个答案:

答案 0 :(得分:0)

好吧,这是什么:

SELECT l.level
  FROM user_character c
  JOIN character_level l
    ON l.experience <= c.character_current_xp
 WHERE ID = '$currentUser'
 ORDER 
    BY experience DESC 
 LIMIT 1