From 6c6812f81838b7963e25e8ab9ca2f71043bf8886 Mon Sep 17 00:00:00 2001 From: "Igor Barkov (iwork)" Date: Tue, 7 Jul 2020 12:50:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B7=D0=B0=D0=B1=D1=8B=D0=BB=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=20=D1=84=D1=83=D0=BD?= =?UTF-8?q?=D0=BA=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- classes/DressedItems.php | 35 +++++++++++++++++++++++++++-------- classes/User.php | 15 ++++++++------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/classes/DressedItems.php b/classes/DressedItems.php index 59dc43a..d9cce4d 100644 --- a/classes/DressedItems.php +++ b/classes/DressedItems.php @@ -10,26 +10,45 @@ class DressedItems protected $DB; private $dressedItem; - public function __construct() { - // Пустой потому что нужны разные запросы. + public function __construct($user_id) { + $this->userid = $user_id ?? 0; } - private function getDressedItems($user_id) + private function getDressedItems() { try { - return db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot > 0', $user_id); + $this->DB = db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot > 0', $this->userid); + while ($row = $this->DB->fetch_assoc()) { + $dressed_item[$row['dressed_slot']] = $row; + $this->dressedItem[$row['dressed_slot']] = $row; + } } catch (Exception $e) { echo '
getDressedItems: ' . $e . '
'; } - return null; } - public function getSlots($user_id) + public function getSlots() { - while ($row = $this->getDressedItems($user_id)->fetch_assoc()) { + return $this->dressedItem; + } + + private function runQuery($user_id) + { + try { + $this->DB = db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot > 0', $user_id); + } catch (Exception $e) { + echo '
getDressedItems: ' . $e . '
'; + } + } + public function eeee($user_id) + { + if (!$this->DB) { + $this->runQuery($user_id); + } + while ($row = $this->DB->fetch_assoc()) { $dressed_item[$row['dressed_slot']] = $row; $this->dressedItem[$row['dressed_slot']] = $row; } - return $this->dressedItem; } + } \ No newline at end of file diff --git a/classes/User.php b/classes/User.php index 910a7bc..7907eb2 100644 --- a/classes/User.php +++ b/classes/User.php @@ -56,11 +56,12 @@ class User private function UserInfoDoll($isBattle = 0, $isMain = 0) { //https://jsfiddle.net/ngx0yvhc - $dressed_items = db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot > 0', $this->id); - while ($row = $dressed_items->fetch_assoc()) { - $dressed_item[$row['dressed_slot']] = $row; - } +// $dressed_items = db::c()->query('SELECT * FROM inventory WHERE owner_id = ?i AND dressed_slot > 0', $this->id); +// while ($row = $dressed_items->fetch_assoc()) { +// $dressed_item[$row['dressed_slot']] = $row; +// } $di = new DressedItems(); + $di->eeee($this->id); // for ($i = 1; $i <= 12; $i++) { // echo sprintf('
', $i); @@ -79,13 +80,13 @@ class User // } for ($i = 1; $i <= 12; $i++) { echo sprintf('
', $i); - if (isset($di->getSlots($this->id)[$i])) { + if (isset($di->eeee($this->id)[$i])) { if (!$isBattle && $isMain) { $itemString = '%s'; - echo sprintf($itemString, $i, $di->getSlots($this->id)[$i]['image'], $di->getSlots($this->id)[$i]['name'], $di->getSlots($this->id)[$i]['name']); + echo sprintf($itemString, $i, $di->eeee($this->id)[$i]['image'], $di->eeee($this->id)[$i]['name'], $di->eeee($this->id)[$i]['name']); } else { $itemString = '%s%s'; - echo sprintf($itemString, $di->getSlots($this->id)[$i]['image'], $di->getSlots($this->id)[$i]['name'], $di->getSlots($this->id)[$i]['name']); + echo sprintf($itemString, $di->eeee($this->id)[$i]['image'], $di->eeee($this->id)[$i]['name'], $di->eeee($this->id)[$i]['name']); } } else { echo sprintf('Пустой слот [%s]', $i, $i);