• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

PHP foreach+sql querry

Kavvson

Gdy boli cie glowa wez
Joined
Jun 25, 2008
Messages
1,177
Reaction score
72
Location
Poland
Hello:) I would like to recieve help from you:D Im quite sure this is a easy task but i got brain afk:eek:

This is table schema

PHP:
CREATE TABLE IF NOT EXISTS `empire` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `X` int(3) DEFAULT NULL,
  `Y` int(3) DEFAULT NULL,
  `wojo` int(11) DEFAULT NULL,
  `wojd` int(11) NOT NULL,
  `k` int(11) NOT NULL,
  `broni` mediumtext,
  `active` tinyint(1) DEFAULT '0',
  `typ` varchar(15) NOT NULL,
  `owner` varchar(30) NOT NULL,
  UNIQUE KEY `id` (`id`),
  UNIQUE KEY `id_2` (`id`),
  UNIQUE KEY `X` (`X`),
  UNIQUE KEY `X_2` (`X`),
  UNIQUE KEY `Y` (`Y`),
  KEY `id_3` (`id`),
  KEY `id_4` (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=44 ;

All goes about this that i need a foreach loop that will sum me `broni` WHERE `k`= numer from 00 to 99 :( or checks existing entries.

Is this possible.?
 
I have sth like this

PHP:
foreach($mysqli->query('SELECT broni FROM  `empire` WHERE k = 12')->fetch_array() as $statsd)  
    { 

		preg_match('/(\d{3,5}|(\d{3}\s\d{3})?)\sBerserker/', $statsd, $be1);
		preg_match('/(\d{3,5}|(\d{3}\s\d{3})?)\sLucznik/', $statsd, $lu1);
		preg_match('/(\d{3,5}|(\d{3}\s\d{3})?)\sGwardzista/', $statsd, $gw1);
		preg_match('/(\d{3,5}|(\d{3}\s\d{3})?)\sZwiadowca/', $statsd, $zw1);
		preg_match('/(\d{3,5}|(\d{3}\s\d{3})?)\sKusznik/', $statsd, $ku1);
		preg_match('/(\d{3,5}|(\d{3}\s\d{3})?)\sRycerz/', $statsd, $ry1);
		preg_match('/(\d{3,5}|(\d{3}\s\d{3})?)\sMag/', $statsd, $ma1);
		preg_match('/(\d{3,5}|(\d{3}\s\d{3})?)\sCzarodziej/', $statsd, $cz1);
		preg_match('/(\d{3,5}|(\d{3}\s\d{3})?)\sTemplariusz/', $statsd, $te1);
		preg_match('/(\d{3,5}|(\d{3}\s\d{3})?)\sPalladyn/', $statsd, $pa1);
		preg_match('/(\d{3,5}|(\d{3}\s\d{3})?)\sBaron/', $statsd, $ba1);
		preg_match('/(\d{3,5}|(\d{3}\s\d{3})?)\sTaran/', $statsd, $ta1);
		preg_match('/(\d{3,5}|(\d{3}\s\d{3})?)\sBalista/', $statsd, $bal1);
		preg_match('/(\d{3,5}|(\d{3}\s\d{3})?)\sKatapulta/', $statsd, $kat1);
		preg_match('/(\d{3,5}|(\d{3}\s\d{3})?)\sSloop/', $statsd, $slo1);
		preg_match('/(\d{3,5}|(\d{3}\s\d{3})?)\sFregata/', $statsd, $fr1);
		preg_match('/(\d{3,5}|(\d{3}\s\d{3})?)\sGaleon Wojenny/', $statsd, $ga1);	
      
       
           echo $be1[0];
		   var_dump($be1);
    }
200 Berserkerarray(2) { [0]=> string(13) "200 Berserker" [1]=> string(3) "200" } 200 Berserkerarray(2) { [0]=> string(13) "200 Berserker" [1]=> string(3) "200" }
it works but i need a loop for 'k' that will sum me this values.
 
Back
Top