Выводит не только общий онлайн, а ещё и онлайн орды и альянса в таком виде 76+63 = 139 и в конце выводит общий онлайн для всех реалмов Общий 139 (в данном случае)
Code
<?php $conf = array( "db_host" => "localhost", // Ип базы данных mysql "db_login" => "root", // Логин базы mysql "db_pass" => "6655", // Пароль базы mysql // Реалм 1 "realm1" => "characters", // Название базы персонажей "name1" => "x1", // Название реалма // Реалм 2 "realm2" => "", // Название базы персонажей "name2" => "x10", // Название реалма // Реалм 3 "realm3" => "", // Название базы персонажей "name3" => "x25", // Название реалма );
echo "<table width='200' cellpadding='2' border='0'><tr><td colspan='2' align='center'>Онлайн</font></td></tr>"; $conn = mysql_connect("$conf[db_host]","$conf[db_login]","$conf[db_pass]")or die("Невозможно соединиться: " . mysql_error()); if ($conf[realm1] != '') { mysql_selectdb ("$conf[realm1]"); $online1 = mysql_query ("select count(*) from characters where online = 1"); $online1 = mysql_result ($online1,0); $alliance1 = mysql_query ("select count(*) from characters where online = 1 and race in (1,3,4,7,11)"); $alliance1 = mysql_result ($alliance1,0); $horde1 = mysql_query ("select count(*) from characters where online = 1 and race in (2,5,6,8,10)"); $horde1 = mysql_result ($horde1,0); echo "<tr> <td width='100'>$conf[name1]</td> <td width='100'>$alliance1+$horde1 = $online1</td> </tr>";} if ($conf[realm2] != '') { mysql_selectdb ("$conf[realm2]"); $online2 = mysql_query ("select count(*) from characters where online = 1"); $online2 = mysql_result ($online2,0); $alliance2 = mysql_query ("select count(*) from characters where online = 1 and race in (1,3,4,7,11)"); $alliance2 = mysql_result ($alliance2,0); $horde2 = mysql_query ("select count(*) from characters where online = 1 and race in (2,5,6,8,10)"); $horde2 = mysql_result ($horde2,0); echo "<tr> <td width='100'>$conf[name2]</td> <td width='100'>$alliance2+$horde2 = $online2</td> </tr>";} if ($conf[realm3] != '') { mysql_selectdb ("$conf[realm3]"); $online3 = mysql_query ("select count(*) from characters where online = 1"); $online3 = mysql_result ($online3,0); $alliance3 = mysql_query ("select count(*) from characters where online = 1 and race in (1,3,4,7,11)"); $alliance3 = mysql_result ($alliance3,0); $horde3 = mysql_query ("select count(*) from characters where online = 1 and race in (2,5,6,8,10)"); $horde3 = mysql_result ($horde3,0); echo "<tr> <td width='100'>$conf[name3]</td> <td width='100'>$alliance3+$horde3 = $online3</td> </tr>";} $allonline = $online1+$online2+$online3; echo "<tr> <td width='100'>Всего:</td> <td width='100'>$allonline</td> </tr>"; echo "</table>"; mysql_close($conn); ?>
как сделать это с помощью функции ?
Code
function GetOnline($db, $name, $connected){ if(!$connected) $conn = mysql_connect($host, $user, $pass)or die("Невозможно соединиться: " . mysql_error()); mysql_selectdb ($db); $alliance1 = mysql_query ("select count(*) from characters where online = 1 and race in (1,3,4,7,11)"); $alliance = mysql_result ($alliance1,0); $horde1 = mysql_query ("select count(*) from characters where online = 1 and race in (2,5,6,8,10)"); $horde= mysql_result ($horde1,0); echo "<tr> <td width='100'>$name</td> <td width='100'>$alliance+$horde = ".($alliance+$horde)."</td> </tr>"; return ($alliance+$horde); }