There are 30 variables, each of them stores values:
$level1 = 36; $level2 = 72; $level3 = 144; $level4 = 288;
There is a scenario that looks at the amount of experience (value of variables), if the experience is suitable, then it sends to the database level. Scenario:
if ($experience <= $level1) { $result = mysql_query("UPDATE $db_table SET level = 1 WHERE id ='$id'"); } else { if ($experience <= $level2) { $result = mysql_query("UPDATE $db_table SET level = 1 WHERE id ='$id'"); } else { if ($experience <= $level3) { $result = mysql_query("UPDATE $db_table SET level = 2 WHERE id ='$id'"); } else { if ($experience <= $level4) { $result = mysql_query("UPDATE $db_table SET level = 3 WHERE id ='$id'"); } else { if ($experience <= $level5) { $result = mysql_query("UPDATE $db_table SET level = 4 WHERE id ='$id'"); } } } } }
As can be seen from the script, each action is almost repeated, the code is long, can it be reduced?