Возможно ли нагрузка в данном кодинге? PHP + MYSQL
function endb_t($bat){
$hpt=mysql_query("SELECT `fight_users`.`battle`, `fight_users`.`side`, Sum( `fight_users`.`hp` ) AS hp, Sum( `user`.`level` ) AS `level` FROM `fight_users`,`user` WHERE `fight_users`.`id`=`user`.`id` GROUP BY `fight_users`.`side`, `fight_users`.`battle` HAVING (((`fight_users`.`battle`) = '".$bat."')) ORDER BY `fight_users`.`side` LIMIT 2");
while ($hp = mysql_fetch_assoc($hpt)) {
$sid[$hp['side']]=$hp['hp'];
$win[$hp['side']]=$hp['level'];
}
if($sid[1]==0 and $sid[2]!=0){
$win[0]=2;
}else if($sid[2]==0 and $sid[1]!=0){
$win[0]=1;
}else if($sid[1]==0 and $sid[2]==0){
$win[0]=3;
}else{
$win[0]=0;
}
return $win;
}
И помогите пожалуйста, как переписать данный код под $mysqli?
Ответы (1 шт):
Автор решения: uberchel
→ Ссылка
Конечно но некретично, скорее у вас связано с ошибками (не инициализированы переменные) и тем, что вы не удаляйте выборку после запроса.
function endb_t (&$db_connect, $bat) {
if (!empty($db_connect) && isset($bat)) {
$hpt = mysqli_query($db_connect, "SELECT f.battle, f.side, Sum(f.hp) AS hp, Sum(u.level) AS level FROM fight_users f JOIN user u USING(id) GROUP BY f.side, f.battle HAVING f.battle = '{$bat}' ORDER BY f.side LIMIT 2");
if (!empty($hpt) && mysqli_num_rows($hpt) > 0) {
$sid = array();
$win = array();
while ($hp = mysqli_fetch_assoc($hpt)) {
$sid[$hp['side']] = $hp['hp'];
$win[$hp['side']] = $hp['level'];
}
mysqli_free_result($hpt);
if ($sid[1]==0 and $sid[2]!=0) $win[0]=2;
else if ($sid[2]==0 and $sid[1]!=0) $win[0]=1;
else if ($sid[1]==0 and $sid[2]==0) $win[0]=3;
else $win[0]=0;
return $win;
}
}
return null;
}