Как вывести количества планет и количество лун игрока?
This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.
-
-
Добавить переменные в empire.php примерно так не совсем уверен
сам запрос
$db = Database::get();
$db_erg = $db->select("planet FROM uni1_planets");
затем - добавить переменную
'planet' => $uni1_planets,
и затем вывести в тпл в нужное место указать {$planet|number}
не совсем верно думаю .. я не делал... позже тоже надо вывести . позже точно скажу , а так на скорую руку, но работай в этом направление.. если что меня поправят тутThe post was edited 1 time, last by Shandow ().
-
-
PHP Source Code
- <?php
- /**
- * 2Moons
- * by Jan-Otto Kröpke 2009-2016
- *
- * For the full copyright and license information, please view the LICENSE
- *
- * @package 2Moons
- * @author Jan-Otto Kröpke <slaver7@gmail.com>
- * @copyright 2009 Lucky
- * @copyright 2016 Jan-Otto Kröpke <slaver7@gmail.com>
- * @licence MIT
- * @version 1.8.0
- * @link https://github.com/jkroepke/2Moons
- */
- class ShowImperiumPage extends AbstractGamePage
- {
- public static $requireModule = MODULE_IMPERIUM;
- function __construct()
- {
- parent::__construct();
- }
- function show()
- {
- global $USER, $PLANET, $resource, $reslist;
- $db = Database::get();
- switch($USER['planet_sort'])
- {
- case 2:
- $orderBy = 'name';
- break;
- case 1:
- $orderBy = 'galaxy, system, planet, planet_type';
- break;
- default:
- $orderBy = 'id';
- break;
- }
- $orderBy .= ' '.($USER['planet_sort_order'] == 1) ? 'DESC' : 'ASC';
- $sql = "SELECT * FROM %%PLANETS%% WHERE id != :planetID AND id_owner = :userID AND destruyed = '0' ORDER BY :order;";
- $PlanetsRAW = $db->select($sql, array(
- ':planetID' => $PLANET['id'],
- ':userID' => $USER['id'],
- ':order' => $orderBy,
- ));
- $PLANETS = array($PLANET);
- $PlanetRess = new ResourceUpdate();
- foreach ($PlanetsRAW as $CPLANET)
- {
- list($USER, $CPLANET) = $PlanetRess->CalcResource($USER, $CPLANET, true);
- $PLANETS[] = $CPLANET;
- unset($CPLANET);
- }
- $planetList = array();
- foreach($PLANETS as $Planet)
- {
- $planetList['name'][$Planet['id']] = $Planet['name'];
- $planetList['image'][$Planet['id']] = $Planet['image'];
- $planetList['coords'][$Planet['id']]['galaxy'] = $Planet['galaxy'];
- $planetList['coords'][$Planet['id']]['system'] = $Planet['system'];
- $planetList['coords'][$Planet['id']]['planet'] = $Planet['planet'];
- $planetList['field'][$Planet['id']]['current'] = $Planet['field_current'];
- $planetList['field'][$Planet['id']]['max'] = CalculateMaxPlanetFields($Planet);
- $planetList['energy_used'][$Planet['id']] = $Planet['energy'] + $Planet['energy_used'];
- $planetList['resource'][901][$Planet['id']] = $Planet['metal'];
- $planetList['resource'][902][$Planet['id']] = $Planet['crystal'];
- $planetList['resource'][903][$Planet['id']] = $Planet['deuterium'];
- $planetList['resource'][911][$Planet['id']] = $Planet['energy'];
- foreach($reslist['build'] as $elementID) {
- $planetList['build'][$elementID][$Planet['id']] = $Planet[$resource[$elementID]];
- }
- foreach($reslist['fleet'] as $elementID) {
- $planetList['fleet'][$elementID][$Planet['id']] = $Planet[$resource[$elementID]];
- }
- foreach($reslist['defense'] as $elementID) {
- $planetList['defense'][$elementID][$Planet['id']] = $Planet[$resource[$elementID]];
- }
- }
- foreach($reslist['tech'] as $elementID){
- $planetList['tech'][$elementID] = $USER[$resource[$elementID]];
- }
- $this->assign(array(
- 'colspan' => count($PLANETS) + 2,
- 'planetList' => $planetList,
- ));
- $this->display('page.empire.default.tpl');
- }
- }
-
PHP Source Code
- <?php
- /**
- * 2Moons
- * by Jan-Otto Kröpke 2009-2016
- *
- * For the full copyright and license information, please view the LICENSE
- *
- * @package 2Moons
- * @author Jan-Otto Kröpke <slaver7@gmail.com>
- * @copyright 2009 Lucky
- * @copyright 2016 Jan-Otto Kröpke <slaver7@gmail.com>
- * @licence MIT
- * @version 1.8.0
- * @link https://github.com/jkroepke/2Moons
- */
- class ShowImperiumPage extends AbstractGamePage
- {
- public static $requireModule = MODULE_IMPERIUM;
- function __construct()
- {
- parent::__construct();
- }
- function show()
- {
- global $USER, $PLANET, $resource, $reslist;
- $db = Database::get();
- switch($USER['planet_sort'])
- {
- case 2:
- $orderBy = 'name';
- break;
- case 1:
- $orderBy = 'galaxy, system, planet, planet_type';
- break;
- default:
- $orderBy = 'id';
- break;
- }
- $orderBy .= ' '.($USER['planet_sort_order'] == 1) ? 'DESC' : 'ASC';
- $sql = "SELECT * FROM %%PLANETS%% WHERE id != :planetID AND id_owner = :userID AND destruyed = '0' ORDER BY :order;";
- $PlanetsRAW = $db->select($sql, array(
- ':planetID' => $PLANET['id'],
- ':userID' => $USER['id'],
- ':order' => $orderBy,
- ));
- $PLANETS = array($PLANET);
- $PlanetRess = new ResourceUpdate();
- foreach ($PlanetsRAW as $CPLANET)
- {
- list($USER, $CPLANET) = $PlanetRess->CalcResource($USER, $CPLANET, true);
- $PLANETS[] = $CPLANET;
- unset($CPLANET);
- }
- $planetList = array();
- foreach($PLANETS as $Planet)
- {
- $planetList['name'][$Planet['id']] = $Planet['name'];
- $planetList['image'][$Planet['id']] = $Planet['image'];
- $planetList['coords'][$Planet['id']]['galaxy'] = $Planet['galaxy'];
- $planetList['coords'][$Planet['id']]['system'] = $Planet['system'];
- $planetList['coords'][$Planet['id']]['planet'] = $Planet['planet'];
- $planetList['field'][$Planet['id']]['current'] = $Planet['field_current'];
- $planetList['field'][$Planet['id']]['max'] = CalculateMaxPlanetFields($Planet);
- $planetList['energy_used'][$Planet['id']] = $Planet['energy'] + $Planet['energy_used'];
- $planetList['resource'][901][$Planet['id']] = $Planet['metal'];
- $planetList['resource'][902][$Planet['id']] = $Planet['crystal'];
- $planetList['resource'][903][$Planet['id']] = $Planet['deuterium'];
- $planetList['resource'][911][$Planet['id']] = $Planet['energy'];
- foreach($reslist['build'] as $elementID) {
- $planetList['build'][$elementID][$Planet['id']] = $Planet[$resource[$elementID]];
- }
- foreach($reslist['fleet'] as $elementID) {
- $planetList['fleet'][$elementID][$Planet['id']] = $Planet[$resource[$elementID]];
- }
- foreach($reslist['defense'] as $elementID) {
- $planetList['defense'][$elementID][$Planet['id']] = $Planet[$resource[$elementID]];
- }
- }
- foreach($reslist['tech'] as $elementID){
- $planetList['tech'][$elementID] = $USER[$resource[$elementID]];
- }
- // нам нужны планеты, ок.
- $planetcount = "SELECT COUNT(*) FROM %%PLANETS%% WHERE planet_type = 1 AND id_owner = :userID;";
- $PlanetsRAW = $db->select($sql, array(
- ':userID' => $USER['id'],
- ));
- $this->assign(array(
- 'colspan' => count($PLANETS) + 2,
- 'planetList' => $planetList,
- 'countplanet' => $planetcount,
- ));
- $this->display('page.empire.default.tpl');
- }
- }
З.Ы. писал все это с телефона, проверить сам не могу, так что если что сильно не ругайте)Кто к нам с чем зачем, тот от того и того! -
Только сейчас заметил, есть совсем уж простой способ вывести цифру всех планет и лун)) обрати внимание на строку
count($PLANETS)
ИМХО самый простой вывод))Кто к нам с чем зачем, тот от того и того! -
aurum79 wrote:
Только сейчас заметил, есть совсем уж простой способ вывести цифру всех планет и лун)) обрати внимание на строку
count($PLANETS)
ИМХО самый простой вывод))
А мне надо количество планет отдельно лун отдельно. -
aurum79 wrote:
PHP Source Code
- <?php
- /**
- * 2Moons
- * by Jan-Otto Kröpke 2009-2016
- *
- * For the full copyright and license information, please view the LICENSE
- *
- * @package 2Moons
- * @author Jan-Otto Kröpke <slaver7@gmail.com>
- * @copyright 2009 Lucky
- * @copyright 2016 Jan-Otto Kröpke <slaver7@gmail.com>
- * @licence MIT
- * @version 1.8.0
- * @link https://github.com/jkroepke/2Moons
- */
- class ShowImperiumPage extends AbstractGamePage
- {
- public static $requireModule = MODULE_IMPERIUM;
- function __construct()
- {
- parent::__construct();
- }
- function show()
- {
- global $USER, $PLANET, $resource, $reslist;
- $db = Database::get();
- switch($USER['planet_sort'])
- {
- case 2:
- $orderBy = 'name';
- break;
- case 1:
- $orderBy = 'galaxy, system, planet, planet_type';
- break;
- default:
- $orderBy = 'id';
- break;
- }
- $orderBy .= ' '.($USER['planet_sort_order'] == 1) ? 'DESC' : 'ASC';
- $sql = "SELECT * FROM %%PLANETS%% WHERE id != :planetID AND id_owner = :userID AND destruyed = '0' ORDER BY :order;";
- $PlanetsRAW = $db->select($sql, array(
- ':planetID' => $PLANET['id'],
- ':userID' => $USER['id'],
- ':order' => $orderBy,
- ));
- $PLANETS = array($PLANET);
- $PlanetRess = new ResourceUpdate();
- foreach ($PlanetsRAW as $CPLANET)
- {
- list($USER, $CPLANET) = $PlanetRess->CalcResource($USER, $CPLANET, true);
- $PLANETS[] = $CPLANET;
- unset($CPLANET);
- }
- $planetList = array();
- foreach($PLANETS as $Planet)
- {
- $planetList['name'][$Planet['id']] = $Planet['name'];
- $planetList['image'][$Planet['id']] = $Planet['image'];
- $planetList['coords'][$Planet['id']]['galaxy'] = $Planet['galaxy'];
- $planetList['coords'][$Planet['id']]['system'] = $Planet['system'];
- $planetList['coords'][$Planet['id']]['planet'] = $Planet['planet'];
- $planetList['field'][$Planet['id']]['current'] = $Planet['field_current'];
- $planetList['field'][$Planet['id']]['max'] = CalculateMaxPlanetFields($Planet);
- $planetList['energy_used'][$Planet['id']] = $Planet['energy'] + $Planet['energy_used'];
- $planetList['resource'][901][$Planet['id']] = $Planet['metal'];
- $planetList['resource'][902][$Planet['id']] = $Planet['crystal'];
- $planetList['resource'][903][$Planet['id']] = $Planet['deuterium'];
- $planetList['resource'][911][$Planet['id']] = $Planet['energy'];
- foreach($reslist['build'] as $elementID) {
- $planetList['build'][$elementID][$Planet['id']] = $Planet[$resource[$elementID]];
- }
- foreach($reslist['fleet'] as $elementID) {
- $planetList['fleet'][$elementID][$Planet['id']] = $Planet[$resource[$elementID]];
- }
- foreach($reslist['defense'] as $elementID) {
- $planetList['defense'][$elementID][$Planet['id']] = $Planet[$resource[$elementID]];
- }
- }
- foreach($reslist['tech'] as $elementID){
- $planetList['tech'][$elementID] = $USER[$resource[$elementID]];
- }
- // нам нужны планеты, ок.
- $planetcount = "SELECT COUNT(*) FROM %%PLANETS%% WHERE planet_type = 1 AND id_owner = :userID;";
- $PlanetsRAW = $db->select($sql, array(
- ':userID' => $USER['id'],
- ));
- $this->assign(array(
- 'colspan' => count($PLANETS) + 2,
- 'planetList' => $planetList,
- 'countplanet' => $planetcount,
- ));
- $this->display('page.empire.default.tpl');
- }
- }
З.Ы. писал все это с телефона, проверить сам не могу, так что если что сильно не ругайте)
Message: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
Query-Code:SELECT * FROM uni1_planets WHERE id != :planetID AND id_owner = 1 AND destruyed = '0' ORDER BY :order;
File: /includes/classes/Database.class.php
Line: 126
URL: 2moons18.loc/game.php?page=imperium
PHP-Version: 5.6.32
PHP-API: apache2handler
2Moons Version: 1.8.git
Debug Backtrace:
#0 /includes/classes/Database.class.php(193): Database->_query('SELECT * FROM %...', Array, 'select')
#1 /includes/pages/game/ShowImperiumPage.class.php(110): Database->select('SELECT * FROM %...', Array)
#2 /game.php(57): ShowImperiumPage->show()
#3 {main} -
-
-
это тебе выдаст только подсчет планет, без лун. А на счет ошибки, ошибку выдает не в моих строчках, залей чистую версию и добавь мои строкиКто к нам с чем зачем, тот от того и того!
-
aurum79 wrote:
это тебе выдаст только подсчет планет, без лун. А на счет ошибки, ошибку выдает не в моих строчках, залей чистую версию и добавь мои строки
Поставил с нуля движок и все ровно дает ошибку после добавления твоих строк.
-
Ну извини,я с телефона,комп в ремонте, проверить никак не могу увы,еаэтой неделе починю скорей всегоКто к нам с чем зачем, тот от того и того!
-
Упс! Нашел ошибку в своем же коде, извини, поправил, пользуйся, теперь все норм должно быть (проверить все так же не могу пока что)
PHP Source Code
- <?php
- /**
- * 2Moons
- * by Jan-Otto Kröpke 2009-2016
- *
- * For the full copyright and license information, please view the LICENSE
- *
- * @package 2Moons
- * @author Jan-Otto Kröpke <slaver7@gmail.com>
- * @copyright 2009 Lucky
- * @copyright 2016 Jan-Otto Kröpke <slaver7@gmail.com>
- * @licence MIT
- * @version 1.8.0
- * @link https://github.com/jkroepke/2Moons
- */
- class ShowImperiumPage extends AbstractGamePage
- {
- public static $requireModule = MODULE_IMPERIUM;
- function __construct()
- {
- parent::__construct();
- }
- function show()
- {
- global $USER, $PLANET, $resource, $reslist;
- $db = Database::get();
- switch($USER['planet_sort'])
- {
- case 2:
- $orderBy = 'name';
- break;
- case 1:
- $orderBy = 'galaxy, system, planet, planet_type';
- break;
- default:
- $orderBy = 'id';
- break;
- }
- $orderBy .= ' '.($USER['planet_sort_order'] == 1) ? 'DESC' : 'ASC';
- $sql = "SELECT * FROM %%PLANETS%% WHERE id != :planetID AND id_owner = :userID AND destruyed = '0' ORDER BY :order;";
- $PlanetsRAW = $db->select($sql, array(
- ':planetID' => $PLANET['id'],
- ':userID' => $USER['id'],
- ':order' => $orderBy,
- ));
- $PLANETS = array($PLANET);
- $PlanetRess = new ResourceUpdate();
- foreach ($PlanetsRAW as $CPLANET)
- {
- list($USER, $CPLANET) = $PlanetRess->CalcResource($USER, $CPLANET, true);
- $PLANETS[] = $CPLANET;
- unset($CPLANET);
- }
- $planetList = array();
- foreach($PLANETS as $Planet)
- {
- $planetList['name'][$Planet['id']] = $Planet['name'];
- $planetList['image'][$Planet['id']] = $Planet['image'];
- $planetList['coords'][$Planet['id']]['galaxy'] = $Planet['galaxy'];
- $planetList['coords'][$Planet['id']]['system'] = $Planet['system'];
- $planetList['coords'][$Planet['id']]['planet'] = $Planet['planet'];
- $planetList['field'][$Planet['id']]['current'] = $Planet['field_current'];
- $planetList['field'][$Planet['id']]['max'] = CalculateMaxPlanetFields($Planet);
- $planetList['energy_used'][$Planet['id']] = $Planet['energy'] + $Planet['energy_used'];
- $planetList['resource'][901][$Planet['id']] = $Planet['metal'];
- $planetList['resource'][902][$Planet['id']] = $Planet['crystal'];
- $planetList['resource'][903][$Planet['id']] = $Planet['deuterium'];
- $planetList['resource'][911][$Planet['id']] = $Planet['energy'];
- foreach($reslist['build'] as $elementID) {
- $planetList['build'][$elementID][$Planet['id']] = $Planet[$resource[$elementID]];
- }
- foreach($reslist['fleet'] as $elementID) {
- $planetList['fleet'][$elementID][$Planet['id']] = $Planet[$resource[$elementID]];
- }
- foreach($reslist['defense'] as $elementID) {
- $planetList['defense'][$elementID][$Planet['id']] = $Planet[$resource[$elementID]];
- }
- }
- foreach($reslist['tech'] as $elementID){
- $planetList['tech'][$elementID] = $USER[$resource[$elementID]];
- }
- // нам нужны планеты, ок.
- $planetcount = $db->select("SELECT * FROM %%PLANETS%% WHERE planet_type = 1 AND id_owner = :usetID;", array(
- ':userID' => $USER['id']
- ));
- $countplan = $db->rowCount($planetcount);
- $this->assign(array(
- 'colspan' => count($PLANETS) + 2,
- 'planetList' => $planetList,
- 'countplanet' => $countplan,
- ));
- $this->display('page.empire.default.tpl');
- }
- }
Кто к нам с чем зачем, тот от того и того! -
replace the planet_type = 1 in planet_type = 3 which will give you the moon number of the player. copy before the sql queries for the planet numbers which is correctYou can contact me by Discord or Telegram
Discord Galactic Conquest
Video Youtube dev + tutorials
Webside -
aurum79 wrote:
Упс! Нашел ошибку в своем же коде, извини, поправил, пользуйся, теперь все норм должно быть (проверить все так же не могу пока что)
PHP Source Code
- <?php
- /**
- * 2Moons
- * by Jan-Otto Kröpke 2009-2016
- *
- * For the full copyright and license information, please view the LICENSE
- *
- * @package 2Moons
- * @author Jan-Otto Kröpke <slaver7@gmail.com>
- * @copyright 2009 Lucky
- * @copyright 2016 Jan-Otto Kröpke <slaver7@gmail.com>
- * @licence MIT
- * @version 1.8.0
- * @link https://github.com/jkroepke/2Moons
- */
- class ShowImperiumPage extends AbstractGamePage
- {
- public static $requireModule = MODULE_IMPERIUM;
- function __construct()
- {
- parent::__construct();
- }
- function show()
- {
- global $USER, $PLANET, $resource, $reslist;
- $db = Database::get();
- switch($USER['planet_sort'])
- {
- case 2:
- $orderBy = 'name';
- break;
- case 1:
- $orderBy = 'galaxy, system, planet, planet_type';
- break;
- default:
- $orderBy = 'id';
- break;
- }
- $orderBy .= ' '.($USER['planet_sort_order'] == 1) ? 'DESC' : 'ASC';
- $sql = "SELECT * FROM %%PLANETS%% WHERE id != :planetID AND id_owner = :userID AND destruyed = '0' ORDER BY :order;";
- $PlanetsRAW = $db->select($sql, array(
- ':planetID' => $PLANET['id'],
- ':userID' => $USER['id'],
- ':order' => $orderBy,
- ));
- $PLANETS = array($PLANET);
- $PlanetRess = new ResourceUpdate();
- foreach ($PlanetsRAW as $CPLANET)
- {
- list($USER, $CPLANET) = $PlanetRess->CalcResource($USER, $CPLANET, true);
- $PLANETS[] = $CPLANET;
- unset($CPLANET);
- }
- $planetList = array();
- foreach($PLANETS as $Planet)
- {
- $planetList['name'][$Planet['id']] = $Planet['name'];
- $planetList['image'][$Planet['id']] = $Planet['image'];
- $planetList['coords'][$Planet['id']]['galaxy'] = $Planet['galaxy'];
- $planetList['coords'][$Planet['id']]['system'] = $Planet['system'];
- $planetList['coords'][$Planet['id']]['planet'] = $Planet['planet'];
- $planetList['field'][$Planet['id']]['current'] = $Planet['field_current'];
- $planetList['field'][$Planet['id']]['max'] = CalculateMaxPlanetFields($Planet);
- $planetList['energy_used'][$Planet['id']] = $Planet['energy'] + $Planet['energy_used'];
- $planetList['resource'][901][$Planet['id']] = $Planet['metal'];
- $planetList['resource'][902][$Planet['id']] = $Planet['crystal'];
- $planetList['resource'][903][$Planet['id']] = $Planet['deuterium'];
- $planetList['resource'][911][$Planet['id']] = $Planet['energy'];
- foreach($reslist['build'] as $elementID) {
- $planetList['build'][$elementID][$Planet['id']] = $Planet[$resource[$elementID]];
- }
- foreach($reslist['fleet'] as $elementID) {
- $planetList['fleet'][$elementID][$Planet['id']] = $Planet[$resource[$elementID]];
- }
- foreach($reslist['defense'] as $elementID) {
- $planetList['defense'][$elementID][$Planet['id']] = $Planet[$resource[$elementID]];
- }
- }
- foreach($reslist['tech'] as $elementID){
- $planetList['tech'][$elementID] = $USER[$resource[$elementID]];
- }
- // нам нужны планеты, ок.
- $planetcount = $db->select("SELECT * FROM %%PLANETS%% WHERE planet_type = 1 AND id_owner = :usetID;", array(
- ':userID' => $USER['id']
- ));
- $countplan = $db->rowCount($planetcount);
- $this->assign(array(
- 'colspan' => count($PLANETS) + 2,
- 'planetList' => $planetList,
- 'countplanet' => $countplan,
- ));
- $this->display('page.empire.default.tpl');
- }
- }
-
Во я дебил.... usetID замени на userID !
Ппц)) с телефона сложно править)))
97 строкаКто к нам с чем зачем, тот от того и того! -
большинство и на компе не сможет ))
-
aurum79 wrote:
Во я дебил.... usetID замени на userID !
Ппц)) с телефона сложно править)))
97 строка
Все работает теперь. -
Попробовал использовать такой же код только к лунам показывает 0 лун
Вроде planet_type = 3 поставил.
-
Share
- Facebook 0
- Twitter 0
- Google Plus 0
- Reddit 0