From 568cb61bb8b6faf071ebddc6a46055f1205f25f3 Mon Sep 17 00:00:00 2001 From: Olga Marinina Date: Sun, 22 May 2022 21:03:39 +0700 Subject: [PATCH 01/15] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=B2=D1=8B=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BB=D0=BE=D1=82=D0=BE=D0=B2,=20=D0=B4=D0=BE?= =?UTF-8?q?=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D1=85=20=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=BB=D0=BE=D1=81=D1=8C=20=D1=87=D0=B0=D1=81=20?= =?UTF-8?q?=D0=B8=20=D0=BC=D0=B5=D0=BD=D1=8C=D1=88=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- myfunction.php | 18 +++++++++++++++++- templates/main.php | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/myfunction.php b/myfunction.php index aa23d07..0d437bd 100644 --- a/myfunction.php +++ b/myfunction.php @@ -15,7 +15,7 @@ function translate_price($item) /** * Count how much time exist before expiry date of this item * - * @param array $item Array of concrete which contains this date + * @param array $item Array of concrete item which contains this date * * @return int how much time exist */ @@ -26,3 +26,19 @@ function count_time($item) $minutes = floor(($diff - $hours * 3600) / 60); return $hours . ':' . $minutes; } + +/** + * Show so close expiry date from current moment + * + * @param array $item Array of concrete item which contains this date + * + * @return bool true when there is 1 hour left before the expiry date + * and false when there is more than 1 hour left before + */ +function is_expired($item) +{ + if ((strtotime($item['expiry_date']) - strtotime(date('Y-m-d'))) <= 3600) { + return true; + } + return false; +} diff --git a/templates/main.php b/templates/main.php index 8781a76..ea02489 100644 --- a/templates/main.php +++ b/templates/main.php @@ -28,7 +28,7 @@
From 562b52f536dcd23ff31d845137b7d7baece297d6 Mon Sep 17 00:00:00 2001 From: Olga Marinina Date: Sun, 22 May 2022 22:18:35 +0700 Subject: [PATCH 02/15] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80?= =?UTF-8?q?=D1=83=20=D0=B1=D0=B0=D0=B7=D1=8B=20=D0=B4=D0=B0=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- schema.sql | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 schema.sql diff --git a/schema.sql b/schema.sql new file mode 100644 index 0000000..0132a34 --- /dev/null +++ b/schema.sql @@ -0,0 +1,49 @@ +DROP DATABASE IF EXISTS yeticave; + +CREATE DATABASE yeticave + DEFAULT CHARACTER SET utf8 + DEFAULT COLLATE utf8_general_ci; + +USE yeticave; + +CREATE TABLE users ( + id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + dt_add TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + email VARCHAR(128) NOT NULL UNIQUE, + name VARCHAR(255), + password CHAR(255) NOT NULL, + contacts VARCHAR(255) +); + +CREATE TABLE categories ( + id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255), + eng_name VARCHAR(255), +); + +CREATE TABLE items ( + id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + dt_add TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + name VARCHAR(255) NOT NULL, + description TEXT, + image VARCHAR(255) DEFAULT NULL, + first_price INT NOT NULL, + expiry_date TIMESTAMP NOT NULL, + step_bet INT NOT NULL, + author_id INT, + FOREIGN KEY (author_id) REFERENCES users(id), + winner_id INT, + FOREIGN KEY (winner_id) REFERENCES users(id), + category_id INT, + FOREIGN KEY (category_id) REFERENCES categories(id), +); + +CREATE TABLE bets ( + id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + dt_add TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + price INT NOT NULL, + user_id INT, + FOREIGN KEY (user_id) REFERENCES users(id), + item_id INT, + FOREIGN KEY (item_id) REFERENCES items(id), +) From 10881ccda3ba9f09f05621961ba431f8e97a995f Mon Sep 17 00:00:00 2001 From: Olga Marinina Date: Mon, 23 May 2022 07:29:33 +0700 Subject: [PATCH 03/15] =?UTF-8?q?=D0=92=D0=BD=D0=B5=D1=81=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B8,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=B8=D0=BD=D0=B4=D0=B5=D0=BA=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ schema.sql | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index b82d32a..6bf139a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ Thumbs.db vendor uploads/* !uploads/.gitkeep +info.php +adminer.php diff --git a/schema.sql b/schema.sql index 0132a34..f26b733 100644 --- a/schema.sql +++ b/schema.sql @@ -18,7 +18,7 @@ CREATE TABLE users ( CREATE TABLE categories ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), - eng_name VARCHAR(255), + eng_name VARCHAR(255) ); CREATE TABLE items ( @@ -35,7 +35,7 @@ CREATE TABLE items ( winner_id INT, FOREIGN KEY (winner_id) REFERENCES users(id), category_id INT, - FOREIGN KEY (category_id) REFERENCES categories(id), + FOREIGN KEY (category_id) REFERENCES categories(id) ); CREATE TABLE bets ( @@ -45,5 +45,8 @@ CREATE TABLE bets ( user_id INT, FOREIGN KEY (user_id) REFERENCES users(id), item_id INT, - FOREIGN KEY (item_id) REFERENCES items(id), -) + FOREIGN KEY (item_id) REFERENCES items(id) +); + +CREATE INDEX c_name ON categories(name); +CREATE INDEX i_name ON items(name); From 2f7b60a17761a01f705e945f8a6e5a9b772e4697 Mon Sep 17 00:00:00 2001 From: Olga Marinina Date: Wed, 25 May 2022 08:22:35 +0700 Subject: [PATCH 04/15] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=B2=20?= =?UTF-8?q?=D0=B1=D0=B0=D0=B7=D1=83=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- queries.sql | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 queries.sql diff --git a/queries.sql b/queries.sql new file mode 100644 index 0000000..58aab76 --- /dev/null +++ b/queries.sql @@ -0,0 +1,99 @@ +/* Create the list of categories with current categories */ +INSERT INTO categories (name, eng_name) VALUES + ('Доски и лыжи', 'boards'), + ('Крепления', 'attachment'), + ('Ботинки', 'boots'), + ('Одежда', 'clothing'), + ('Инструменты', 'tools'), + ('Разное', 'other'); + +/* Create the list of users */ +INSERT INTO users (email, name, password, contacts) VALUES + ('keks@gmail.com', 'keks', '12578g', 'https://tlgg.ru/keks'), + ('catnotdog@yandex.ru', 'your_cat', 'gav057', 'https://tlgg.ru/your_cat'), + ('kotik@mail.ru', 'kot_ik', '3pv007', 'https://tlgg.ru/kot_ik'); + +INSERT INTO items (name, description, image, first_price, expiry_date, step_bet, author_id, winner_id, category_id) VALUES + ( + '2014 Rossignol District Snowboard', + NULL, + 'img/lot-1.jpg', + 10999, + '2022-05-22', + 500, + (SELECT id FROM users WHERE name = 'keks'), + NULL, + (SELECT id FROM categories WHERE eng_name = 'boards') + ), + ( + 'DC Ply Mens 2016/2017 Snowboard', + NULL, + 'img/lot-2.jpg', + 159999, + '2022-05-23', + 1500, + (SELECT id FROM users WHERE name = 'your_cat'), + NULL, + (SELECT id FROM categories WHERE eng_name = 'boards') + ), + ( + 'Крепления Union Contact Pro 2015 года размер L/XL', + NULL, + 'img/lot-3.jpg', + 8000, + '2022-05-24', + 500, + (SELECT id FROM users WHERE name = 'keks'), + NULL, + (SELECT id FROM categories WHERE eng_name = 'attachment') + ), + ( + 'Ботинки для сноуборда DC Mutiny Charocal', + NULL, + 'img/lot-4.jpg', + 10999, + '2022-05-25', + 500, + (SELECT id FROM users WHERE name = 'kot_ik'), + NULL, + (SELECT id FROM categories WHERE eng_name = 'boots') + ), + ( + 'Куртка для сноуборда DC Mutiny Charocal', + NULL, + 'img/lot-5.jpg', + 7500, + '2022-05-26', + 500, + (SELECT id FROM users WHERE name = 'kot_ik'), + NULL, + (SELECT id FROM categories WHERE eng_name = 'clothing') + ), + ( + 'Маска Oakley Canopy', + NULL, + 'img/lot-6.jpg', + 5400, + '2022-05-27', + 200, + (SELECT id FROM users WHERE name = 'your_cat'), + NULL, + (SELECT id FROM categories WHERE eng_name = 'other') + ); + +INSERT INTO bets (price, user_id, item_id) VALUES + ( + 6000, + (SELECT id FROM users WHERE name = 'kot_ik'), + (SELECT id FROM items WHERE name = 'Маска Oakley Canopy') + ), + ( + 5800, + (SELECT id FROM users WHERE name = 'keks'), + (SELECT id FROM items WHERE name = 'Маска Oakley Canopy') + ), + ( + 9000, + (SELECT id FROM users WHERE name = 'your_cat'), + (SELECT id FROM items WHERE name = 'Крепления Union Contact Pro 2015 года размер L/XL') + ); From 95dc94c6f0928878f56ca517f80843a0ca6b3676 Mon Sep 17 00:00:00 2001 From: Olga Marinina Date: Wed, 25 May 2022 09:06:46 +0700 Subject: [PATCH 05/15] =?UTF-8?q?=D0=9D=D0=B0=D0=BF=D0=B8=D1=81=D0=B0?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D1=8B=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BC=D0=BE=D0=B4=D0=B8=D1=84=D0=B8=D0=BA=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8E=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=20?= =?UTF-8?q?=D0=B2=20=D0=B1=D0=B0=D0=B7=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.php | 2 -- queries.sql | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index db6bfb0..49b17a7 100644 --- a/index.php +++ b/index.php @@ -80,5 +80,3 @@ ); print ($layout_content); - -?> diff --git a/queries.sql b/queries.sql index 58aab76..9686fe3 100644 --- a/queries.sql +++ b/queries.sql @@ -1,4 +1,4 @@ -/* Create the list of categories with current categories */ +/* Create the table of categories with current categories */ INSERT INTO categories (name, eng_name) VALUES ('Доски и лыжи', 'boards'), ('Крепления', 'attachment'), @@ -7,12 +7,13 @@ INSERT INTO categories (name, eng_name) VALUES ('Инструменты', 'tools'), ('Разное', 'other'); -/* Create the list of users */ +/* Create the table of users */ INSERT INTO users (email, name, password, contacts) VALUES ('keks@gmail.com', 'keks', '12578g', 'https://tlgg.ru/keks'), ('catnotdog@yandex.ru', 'your_cat', 'gav057', 'https://tlgg.ru/your_cat'), ('kotik@mail.ru', 'kot_ik', '3pv007', 'https://tlgg.ru/kot_ik'); +/* Create the table of items with current items */ INSERT INTO items (name, description, image, first_price, expiry_date, step_bet, author_id, winner_id, category_id) VALUES ( '2014 Rossignol District Snowboard', @@ -81,6 +82,7 @@ INSERT INTO items (name, description, image, first_price, expiry_date, step_bet, (SELECT id FROM categories WHERE eng_name = 'other') ); +/* Create the table of bets */ INSERT INTO bets (price, user_id, item_id) VALUES ( 6000, @@ -97,3 +99,31 @@ INSERT INTO bets (price, user_id, item_id) VALUES (SELECT id FROM users WHERE name = 'your_cat'), (SELECT id FROM items WHERE name = 'Крепления Union Contact Pro 2015 года размер L/XL') ); + +/* Take all categories */ +SELECT * FROM categories; + +/* Take the newest and opened items */ +SELECT i.name, first_price, image, price, c.name FROM items i + JOIN bets b ON b.item_id = i.id + JOIN categories c ON i.category_id = c.id + WHERE expiry_date > CURRENT_TIMESTAMP + ORDER BY expiry_date DESC; + +/* Take items by its ID */ +SELECT i.name, description, image, first_price, expiry_date, step_bet, u.name, c.name + FROM items i + JOIN users u ON i.user_id = u.id + JOIN categories c ON i.category_id = c.id + WHERE i.id = 2; + +/* Update item_name by its ID */ +UPDATE items SET name = 'Крепления Union Contact Pro 2015 года размер S/M' + WHERE id = 3; + +/* Take the list of bets for the item */ +SELECT i.name, price, u.name FROM bets b + JOIN items i ON b.item_id = i.id + JOIN users u ON b.user_id = u.id + WHERE i.id = 6 + ORDER BY b.dt_add ASC; From 6aa5cc52f832cac051a51dbba39f5b61031fa409 Mon Sep 17 00:00:00 2001 From: Olga Marinina Date: Wed, 25 May 2022 20:23:34 +0700 Subject: [PATCH 06/15] =?UTF-8?q?=D0=92=D0=BD=D0=B5=D1=81=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B2=20=D0=91=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + config/db.php.example | 8 ++++++++ init.php | 1 + 3 files changed, 10 insertions(+) create mode 100644 config/db.php.example diff --git a/.gitignore b/.gitignore index 6bf139a..3f4c034 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ uploads/* !uploads/.gitkeep info.php adminer.php +config/db.php diff --git a/config/db.php.example b/config/db.php.example new file mode 100644 index 0000000..1a2cb8d --- /dev/null +++ b/config/db.php.example @@ -0,0 +1,8 @@ + 'localhost', + 'user' => '', + 'password' => '', + 'database' => 'yeticave' +]; diff --git a/init.php b/init.php index d540faa..970d497 100644 --- a/init.php +++ b/init.php @@ -1,3 +1,4 @@ Date: Wed, 25 May 2022 20:36:50 +0700 Subject: [PATCH 07/15] =?UTF-8?q?=D0=A3=D1=81=D1=82=D0=B0=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB=D0=B0=20=D1=81=D0=BE=D0=B5=D0=B4=D0=B8=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=20=D0=91=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- init.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/init.php b/init.php index 970d497..f085b3a 100644 --- a/init.php +++ b/init.php @@ -2,3 +2,12 @@ require_once 'config/db.php'; date_default_timezone_set('Europe/Moscow'); + +$connect = mysqli_connect($db['host'], $db['user'], $db['password'], $db['database']); +mysqli_set_charset($connect, 'utf8'); + +if (!$connect) { + $dbError = mysqli_connect_error(); + $content = 'Ошибка подключения: ' . $dbError; +}; + From 957e427540137e84a523c6d0ed4fcdd30fce2e0b Mon Sep 17 00:00:00 2001 From: Olga Marinina Date: Wed, 25 May 2022 20:55:24 +0700 Subject: [PATCH 08/15] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80?= =?UTF-8?q?=D1=83=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2=20=D0=B2=20=D0=BF?= =?UTF-8?q?=D0=B0=D0=BF=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++-- myfunction.php => functions/changers.php | 16 ---------------- helpers.php => functions/helpers.php | 0 functions/statings.php | 17 +++++++++++++++++ functions/toMySQL.php | 0 index.php | 6 ++++-- queries.sql => sql/queries.sql | 0 schema.sql => sql/schema.sql | 0 8 files changed, 23 insertions(+), 20 deletions(-) rename myfunction.php => functions/changers.php (61%) rename helpers.php => functions/helpers.php (100%) create mode 100644 functions/statings.php create mode 100644 functions/toMySQL.php rename queries.sql => sql/queries.sql (100%) rename schema.sql => sql/schema.sql (100%) diff --git a/.gitignore b/.gitignore index 3f4c034..980f4bf 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,6 @@ Thumbs.db vendor uploads/* !uploads/.gitkeep -info.php -adminer.php +tools/info.php +tools/adminer.php config/db.php diff --git a/myfunction.php b/functions/changers.php similarity index 61% rename from myfunction.php rename to functions/changers.php index 0d437bd..11624d7 100644 --- a/myfunction.php +++ b/functions/changers.php @@ -26,19 +26,3 @@ function count_time($item) $minutes = floor(($diff - $hours * 3600) / 60); return $hours . ':' . $minutes; } - -/** - * Show so close expiry date from current moment - * - * @param array $item Array of concrete item which contains this date - * - * @return bool true when there is 1 hour left before the expiry date - * and false when there is more than 1 hour left before - */ -function is_expired($item) -{ - if ((strtotime($item['expiry_date']) - strtotime(date('Y-m-d'))) <= 3600) { - return true; - } - return false; -} diff --git a/helpers.php b/functions/helpers.php similarity index 100% rename from helpers.php rename to functions/helpers.php diff --git a/functions/statings.php b/functions/statings.php new file mode 100644 index 0000000..8c03b19 --- /dev/null +++ b/functions/statings.php @@ -0,0 +1,17 @@ + Date: Wed, 25 May 2022 22:24:40 +0700 Subject: [PATCH 09/15] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=B3=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=B8=D0=BB=D0=B0=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=20=D0=BF=D0=BE=D0=B4=D0=BA?= =?UTF-8?q?=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=B8=D0=B7=20=D0=91=D0=94=20(=D1=87=D0=B5?= =?UTF-8?q?=D1=80=D0=BD=D0=BE=D0=B2=D0=B8=D0=BA)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/changers.php | 14 +++++++------- functions/statings.php | 17 ++++++++++++++++- functions/toMySQL.php | 20 ++++++++++++++++++++ index.php | 7 ++++--- init.php | 2 +- templates/main.php | 12 ++++++------ 6 files changed, 54 insertions(+), 18 deletions(-) diff --git a/functions/changers.php b/functions/changers.php index 11624d7..ca7e3b3 100644 --- a/functions/changers.php +++ b/functions/changers.php @@ -7,9 +7,9 @@ * * @return string Update price */ -function translate_price($item) +function changeFormatPrice(array $item) { - return number_format(ceil($item['price']), 0, '', ' ') . ' ₽'; + return number_format(ceil($item['first_price']), 0, '', ' ') . ' ₽'; } /** @@ -19,10 +19,10 @@ function translate_price($item) * * @return int how much time exist */ -function count_time($item) +function countLeftTime(array $item) { - $diff = strtotime($item['expiry_date']) - time(); - $hours = floor($diff / 3600); - $minutes = floor(($diff - $hours * 3600) / 60); - return $hours . ':' . $minutes; + $diffToday = strtotime($item['expiry_date']) - time(); + $leftHours = floor($diffToday / 3600); + $leftMinutes = floor(($diffToday - $leftHours * 3600) / 60); + return $leftHours . ':' . $leftMinutes; } diff --git a/functions/statings.php b/functions/statings.php index 8c03b19..fdae376 100644 --- a/functions/statings.php +++ b/functions/statings.php @@ -8,10 +8,25 @@ * @return bool true when there is 1 hour left before the expiry date * and false when there is more than 1 hour left before */ -function is_expired($item) +function isExpired($item) { if ((strtotime($item['expiry_date']) - strtotime(date('Y-m-d'))) <= 3600) { return true; } return false; } + +/** + * Show exist the result of mysqli_query or we have a mistake + * + * @param mysqli $result response from our database to our request + * + * @return array from DB + */ +function isExistResult($result) +{ + if (!$result) { + exit('Ошибка запроса'); + } + return mysqli_fetch_all($result, MYSQLI_ASSOC); +} diff --git a/functions/toMySQL.php b/functions/toMySQL.php index e69de29..618d180 100644 --- a/functions/toMySQL.php +++ b/functions/toMySQL.php @@ -0,0 +1,20 @@ + CURRENT_TIMESTAMP " + . "ORDER BY expiry_date DESC"; + $newItems = mysqli_query($connect, $takeNewItems); + return isExistResult($newItems);; +} diff --git a/index.php b/index.php index 3d99d7a..510b905 100644 --- a/index.php +++ b/index.php @@ -17,7 +17,8 @@ 'other' => 'Разное' ]; -$items = [ +$newItems = newItems($connect); +/*$items = [ [ 'name' => '2014 Rossignol District Snowboard', 'category' => $categories['boards'], @@ -60,13 +61,13 @@ 'url_image' => 'img/lot-6.jpg', 'expiry_date' => '2022-05-27' ] -]; +];*/ $page_content = include_template( 'main.php', [ 'categories' => $categories, - 'items' => $items + 'items' => $newItems ] ); diff --git a/init.php b/init.php index f085b3a..d762e2d 100644 --- a/init.php +++ b/init.php @@ -8,6 +8,6 @@ if (!$connect) { $dbError = mysqli_connect_error(); - $content = 'Ошибка подключения: ' . $dbError; + $page_content = 'Ошибка подключения: ' . $dbError; }; diff --git a/templates/main.php b/templates/main.php index ea02489..1258e8b 100644 --- a/templates/main.php +++ b/templates/main.php @@ -17,22 +17,22 @@
  • - +
    - -

    + +

    Стартовая цена - +
    - +
    From ce0b76c3803a12e2cb4bfb6acfdc66e164cdf1b7 Mon Sep 17 00:00:00 2001 From: Olga Marinina Date: Thu, 26 May 2022 15:50:33 +0700 Subject: [PATCH 10/15] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=D0=BB=D0=B0=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=BA=D0=B0=D0=B7=20=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D1=80=D1=8B=D1=82=D1=8B=D1=85=20=D0=BB=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/toMySQL.php | 3 +-- index.php | 44 ------------------------------------------- sql/queries.sql | 12 ++++++------ templates/main.php | 6 +++--- 4 files changed, 10 insertions(+), 55 deletions(-) diff --git a/functions/toMySQL.php b/functions/toMySQL.php index 618d180..84a93ad 100644 --- a/functions/toMySQL.php +++ b/functions/toMySQL.php @@ -10,8 +10,7 @@ function newItems(mysqli $connect) { $takeNewItems = "SELECT i.name, first_price, image, DATE_FORMAT(expiry_date, '%d.%m.%Y') " - . "as expiry_date, price, c.name FROM items i " - . "JOIN bets b ON b.item_id = i.id " + . "as expiry_date, c.name as category FROM items i " . "JOIN categories c ON i.category_id = c.id " . "WHERE expiry_date > CURRENT_TIMESTAMP " . "ORDER BY expiry_date DESC"; diff --git a/index.php b/index.php index 510b905..dfff987 100644 --- a/index.php +++ b/index.php @@ -18,50 +18,6 @@ ]; $newItems = newItems($connect); -/*$items = [ - [ - 'name' => '2014 Rossignol District Snowboard', - 'category' => $categories['boards'], - 'price' => 10999, - 'url_image' => 'img/lot-1.jpg', - 'expiry_date' => '2022-05-22' - ], - [ - 'name' => 'DC Ply Mens 2016/2017 Snowboard', - 'category' => $categories['boards'], - 'price' => 159999, - 'url_image' => 'img/lot-2.jpg', - 'expiry_date' => '2022-05-23' - ], - [ - 'name' => 'Крепления Union Contact Pro 2015 года размер L/XL', - 'category' => $categories['attachment'], - 'price' => 8000, - 'url_image' => 'img/lot-3.jpg', - 'expiry_date' => '2022-05-24' - ], - [ - 'name' => 'Ботинки для сноуборда DC Mutiny Charocal', - 'category' => $categories['boots'], - 'price' => 10999, - 'url_image' => 'img/lot-4.jpg', - 'expiry_date' => '2022-05-25' - ], - [ - 'name' => 'Куртка для сноуборда DC Mutiny Charocal', - 'category' => $categories['clothing'], - 'price' => 7500, - 'url_image' => 'img/lot-5.jpg', - 'expiry_date' => '2022-05-26' - ], - [ - 'name' => 'Маска Oakley Canopy', - 'category' => $categories['other'], - 'price' => 5400, - 'url_image' => 'img/lot-6.jpg', - 'expiry_date' => '2022-05-27' - ] -];*/ $page_content = include_template( 'main.php', diff --git a/sql/queries.sql b/sql/queries.sql index 9686fe3..07f0bb6 100644 --- a/sql/queries.sql +++ b/sql/queries.sql @@ -20,7 +20,7 @@ INSERT INTO items (name, description, image, first_price, expiry_date, step_bet, NULL, 'img/lot-1.jpg', 10999, - '2022-05-22', + '2022-05-26', 500, (SELECT id FROM users WHERE name = 'keks'), NULL, @@ -31,7 +31,7 @@ INSERT INTO items (name, description, image, first_price, expiry_date, step_bet, NULL, 'img/lot-2.jpg', 159999, - '2022-05-23', + '2022-05-27', 1500, (SELECT id FROM users WHERE name = 'your_cat'), NULL, @@ -42,7 +42,7 @@ INSERT INTO items (name, description, image, first_price, expiry_date, step_bet, NULL, 'img/lot-3.jpg', 8000, - '2022-05-24', + '2022-05-28', 500, (SELECT id FROM users WHERE name = 'keks'), NULL, @@ -53,7 +53,7 @@ INSERT INTO items (name, description, image, first_price, expiry_date, step_bet, NULL, 'img/lot-4.jpg', 10999, - '2022-05-25', + '2022-05-29', 500, (SELECT id FROM users WHERE name = 'kot_ik'), NULL, @@ -64,7 +64,7 @@ INSERT INTO items (name, description, image, first_price, expiry_date, step_bet, NULL, 'img/lot-5.jpg', 7500, - '2022-05-26', + '2022-05-30', 500, (SELECT id FROM users WHERE name = 'kot_ik'), NULL, @@ -75,7 +75,7 @@ INSERT INTO items (name, description, image, first_price, expiry_date, step_bet, NULL, 'img/lot-6.jpg', 5400, - '2022-05-27', + '2022-05-31', 200, (SELECT id FROM users WHERE name = 'your_cat'), NULL, diff --git a/templates/main.php b/templates/main.php index 1258e8b..0da70e7 100644 --- a/templates/main.php +++ b/templates/main.php @@ -4,7 +4,7 @@
      $category) : ?>
    • - +
    @@ -20,8 +20,8 @@
  • - -

    + +

    Стартовая цена From e32e70f8ee88f2f3562bf7446fc03fabedbdf199 Mon Sep 17 00:00:00 2001 From: Olga Marinina Date: Thu, 26 May 2022 16:01:55 +0700 Subject: [PATCH 11/15] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=BA=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=B8=D0=B7=20?= =?UTF-8?q?=D0=91=D0=94,=20=D0=BF=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B8=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/toMySQL.php | 16 +++++++++++++++- index.php | 11 ++++++----- templates/layout.php | 2 +- templates/main.php | 6 +++--- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/functions/toMySQL.php b/functions/toMySQL.php index 84a93ad..6189d4f 100644 --- a/functions/toMySQL.php +++ b/functions/toMySQL.php @@ -15,5 +15,19 @@ function newItems(mysqli $connect) . "WHERE expiry_date > CURRENT_TIMESTAMP " . "ORDER BY expiry_date DESC"; $newItems = mysqli_query($connect, $takeNewItems); - return isExistResult($newItems);; + return isExistResult($newItems); +} + +/** + * Take the current categories + * + * @param mysqli $connect DB with an categories table + * + * @return array of current categories + */ +function currentCategories(mysqli $connect) +{ + $takeCurrentCategories = "SELECT * FROM categories"; + $currentCategories = mysqli_query($connect, $takeCurrentCategories); + return isExistResult($currentCategories); } diff --git a/index.php b/index.php index dfff987..39f9379 100644 --- a/index.php +++ b/index.php @@ -7,22 +7,23 @@ require_once 'init.php'; $is_auth = rand(0, 1); -$user_name = 'Olga'; // укажите здесь ваше имя -$categories = [ +$user_name = 'Olga'; +$currentCategories = currentCategories($connect); +/*$categories = [ 'boards' =>'Доски и лыжи', 'attachment' => 'Крепления', 'boots' => 'Ботинки', 'clothing' => 'Одежда', 'tools' => 'Инструменты', 'other' => 'Разное' -]; +];*/ $newItems = newItems($connect); $page_content = include_template( 'main.php', [ - 'categories' => $categories, + 'categories' => $currentCategories, 'items' => $newItems ] ); @@ -34,7 +35,7 @@ 'is_auth' => $is_auth, 'user_name' => $user_name, 'content' => $page_content, - 'categories' => $categories + 'categories' => $currentCategories ] ); diff --git a/templates/layout.php b/templates/layout.php index 64e1d5e..9f5bffc 100644 --- a/templates/layout.php +++ b/templates/layout.php @@ -55,7 +55,7 @@ diff --git a/templates/main.php b/templates/main.php index 0da70e7..51fc661 100644 --- a/templates/main.php +++ b/templates/main.php @@ -2,9 +2,9 @@

    Нужен стафф для катки?

    На нашем интернет-аукционе ты найдёшь самое эксклюзивное сноубордическое и горнолыжное снаряжение.

      - $category) : ?> -
    • - + +
    • +
    From 4b88ace2130c34b7270f7b136f1f2ce2dd2850dd Mon Sep 17 00:00:00 2001 From: Olga Marinina Date: Thu, 26 May 2022 16:50:53 +0700 Subject: [PATCH 12/15] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0,=20=D1=87=D1=82=D0=BE=D0=B1=D1=8B=20=D0=BB=D0=BE=D1=82?= =?UTF-8?q?=D1=83=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F=D0=BB=D0=BE?= =?UTF-8?q?=D1=81=D1=8C=20=D0=BA=D0=BE=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=BE=20=D1=81=D1=82=D0=B0=D0=B2=D0=BE=D0=BA=20=D0=B8=20?= =?UTF-8?q?=D0=BC=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=81=D1=82=D0=B0=D0=B2=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/changers.php | 6 +++++- functions/toMySQL.php | 7 +++++-- index.php | 9 --------- templates/main.php | 8 +++++++- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/functions/changers.php b/functions/changers.php index ca7e3b3..b81641a 100644 --- a/functions/changers.php +++ b/functions/changers.php @@ -9,7 +9,11 @@ */ function changeFormatPrice(array $item) { - return number_format(ceil($item['first_price']), 0, '', ' ') . ' ₽'; + $showPrice = $item['first_price']; + if (!empty($item['price'])) { + $showPrice = $item['price']; + } + return number_format(ceil($showPrice), 0, '', ' ') . ' ₽'; } /** diff --git a/functions/toMySQL.php b/functions/toMySQL.php index 6189d4f..39c74f5 100644 --- a/functions/toMySQL.php +++ b/functions/toMySQL.php @@ -9,10 +9,13 @@ */ function newItems(mysqli $connect) { - $takeNewItems = "SELECT i.name, first_price, image, DATE_FORMAT(expiry_date, '%d.%m.%Y') " - . "as expiry_date, c.name as category FROM items i " + $takeNewItems = "SELECT i.id, i.name, first_price, image, DATE_FORMAT(expiry_date, '%d.%m.%Y') " + . "as expiry_date, c.name as category, MAX(price) as price, COUNT(price) as amount_bets " + . "FROM items i " + . "LEFT JOIN bets b ON b.item_id = i.id " . "JOIN categories c ON i.category_id = c.id " . "WHERE expiry_date > CURRENT_TIMESTAMP " + . "GROUP BY i.id " . "ORDER BY expiry_date DESC"; $newItems = mysqli_query($connect, $takeNewItems); return isExistResult($newItems); diff --git a/index.php b/index.php index 39f9379..c0edd60 100644 --- a/index.php +++ b/index.php @@ -9,15 +9,6 @@ $is_auth = rand(0, 1); $user_name = 'Olga'; $currentCategories = currentCategories($connect); -/*$categories = [ - 'boards' =>'Доски и лыжи', - 'attachment' => 'Крепления', - 'boots' => 'Ботинки', - 'clothing' => 'Одежда', - 'tools' => 'Инструменты', - 'other' => 'Разное' -];*/ - $newItems = newItems($connect); $page_content = include_template( diff --git a/templates/main.php b/templates/main.php index 51fc661..903ebc6 100644 --- a/templates/main.php +++ b/templates/main.php @@ -24,7 +24,13 @@

    - Стартовая цена + + + Стартовая цена + + ставок + +
    $currentCategories, + 'item' => $selectedItem + ] +); + +$layout_content = include_template( + 'layout.php', + [ + 'title' => $selectedItem['name'], + 'is_auth' => $is_auth, + 'user_name' => $user_name, + 'content' => $page_content, + 'categories' => $currentCategories + ] +); + +print ($layout_content); diff --git a/templates/lot.php b/templates/lot.php new file mode 100644 index 0000000..0bbd0c3 --- /dev/null +++ b/templates/lot.php @@ -0,0 +1,122 @@ + +
    +

    DC Ply Mens 2016/2017 Snowboard

    +
    +
    +
    + Сноуборд +
    +

    Категория: Доски и лыжи

    +

    Легкий маневренный сноуборд, готовый дать жару в любом парке, растопив + снег + мощным щелчкоми четкими дугами. Стекловолокно Bi-Ax, уложенное в двух направлениях, наделяет этот + снаряд + отличной гибкостью и отзывчивостью, а симметричная геометрия в сочетании с классическим прогибом + кэмбер + позволит уверенно держать высокие скорости. А если к концу катального дня сил совсем не останется, + просто + посмотрите на Вашу доску и улыбнитесь, крутая графика от Шона Кливера еще никого не оставляла + равнодушным.

    +
    +
    +
    +
    + 10:54 +
    +
    +
    + Текущая цена + 10 999 +
    +
    + Мин. ставка 12 000 р +
    +
    +
    +

    + + + Введите наименование лота +

    + +
    +
    +
    +

    История ставок (10)

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Иван10 999 р5 минут назад
    Константин10 999 р20 минут назад
    Евгений10 999 рЧас назад
    Игорь10 999 р19.03.17 в 08:21
    Енакентий10 999 р19.03.17 в 13:20
    Семён10 999 р19.03.17 в 12:20
    Илья10 999 р19.03.17 в 10:20
    Енакентий10 999 р19.03.17 в 13:20
    Семён10 999 р19.03.17 в 12:20
    Илья10 999 р19.03.17 в 10:20
    +
    +
    +
    +
    diff --git a/templates/main.php b/templates/main.php index 903ebc6..5bf2422 100644 --- a/templates/main.php +++ b/templates/main.php @@ -21,7 +21,7 @@
    -

    +

    From 6a56754ee79ef4d105546980fc516770df974db6 Mon Sep 17 00:00:00 2001 From: Olga Marinina Date: Thu, 26 May 2022 19:38:02 +0700 Subject: [PATCH 14/15] =?UTF-8?q?=D0=9E=D0=B6=D0=B8=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=20html,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B4=D1=81=D1=87=D0=B5=D1=82=D0=B0=20=D0=BC=D0=B8=D0=BD?= =?UTF-8?q?=D0=B8=D0=BC=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B9=20=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/changers.php | 17 +++++++++++++ functions/toMySQL.php | 4 ++-- templates/lot.php | 54 ++++++++++++++++-------------------------- 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/functions/changers.php b/functions/changers.php index b81641a..87001d8 100644 --- a/functions/changers.php +++ b/functions/changers.php @@ -30,3 +30,20 @@ function countLeftTime(array $item) $leftMinutes = floor(($diffToday - $leftHours * 3600) / 60); return $leftHours . ':' . $leftMinutes; } + +/** + * Count min bet for current item + * + * @param array $item array of current item + * + * @return int min bet for current item + */ +function countMinBet(array $item) +{ + $currentPrice = $item['first_price']; + if (!empty($item['price'])) { + $currentPrice = $item['price']; + } + $minBet = $currentPrice + $item['step_bet']; + return number_format(ceil($minBet), 0, '', ' ') . ' ₽'; +} diff --git a/functions/toMySQL.php b/functions/toMySQL.php index 0253c1e..784053a 100644 --- a/functions/toMySQL.php +++ b/functions/toMySQL.php @@ -46,12 +46,12 @@ function currentCategories(mysqli $connect) function selectedItem(mysqli $connect, int $itemId) { $takeSelectedItem = "SELECT i.id, i.name, first_price, image, DATE_FORMAT(expiry_date, '%d.%m.%Y') " - . "as expiry_date, c.name as category, MAX(price) as price, step_bet " + . "as expiry_date, c.name as category, MAX(price) as price, step_bet, description " . "FROM items i " . "LEFT JOIN bets b ON b.item_id = i.id " . "JOIN categories c ON i.category_id = c.id " . "WHERE i.id = $itemId " . "GROUP BY i.id "; $selectedItem = mysqli_query($connect, $takeSelectedItem); - return isExistResult($currentCategories)[0]; + return isExistResult($selectedItem)[0]; } diff --git a/templates/lot.php b/templates/lot.php index 0bbd0c3..23c8a8b 100644 --- a/templates/lot.php +++ b/templates/lot.php @@ -1,62 +1,48 @@
    -

    DC Ply Mens 2016/2017 Snowboard

    +

    - Сноуборд + <?= htmlspecialchars($item['name']); ?>
    -

    Категория: Доски и лыжи

    -

    Легкий маневренный сноуборд, готовый дать жару в любом парке, растопив - снег - мощным щелчкоми четкими дугами. Стекловолокно Bi-Ax, уложенное в двух направлениях, наделяет этот - снаряд - отличной гибкостью и отзывчивостью, а симметричная геометрия в сочетании с классическим прогибом - кэмбер - позволит уверенно держать высокие скорости. А если к концу катального дня сил совсем не останется, - просто - посмотрите на Вашу доску и улыбнитесь, крутая графика от Шона Кливера еще никого не оставляла - равнодушным.

    +

    Категория:

    +

    + + + +

    -
    - 10:54 +
    +
    Текущая цена - 10 999 +
    - Мин. ставка 12 000 р + Мин. ставка

    - + Введите наименование лота

    From ff561e3babc962f5bd289506bf2ca8fae4475c1d Mon Sep 17 00:00:00 2001 From: Olga Marinina Date: Fri, 27 May 2022 21:19:48 +0700 Subject: [PATCH 15/15] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BA=D0=B8=20404=20=D0=BF=D1=80=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B5=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=D1=8C=D0=BD=D0=BE?= =?UTF-8?q?=D0=BC=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D0=B5?= =?UTF-8?q?=20itemId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/statings.php | 17 +++++++++++++++++ functions/toMySQL.php | 11 +++++++---- lot.php | 21 +++++++++++++-------- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/functions/statings.php b/functions/statings.php index fdae376..d307811 100644 --- a/functions/statings.php +++ b/functions/statings.php @@ -30,3 +30,20 @@ function isExistResult($result) } return mysqli_fetch_all($result, MYSQLI_ASSOC); } + +/** + * Show error if $itemId is empty or doesn't exist in the item table + * + * @param array $selectedItem the item which is selected by request ID, + * if $itemId is not exist $selectedItem will be null + * + * @return string|null about error with code 404 + */ +function showErrorItemId($selectedItem) +{ + if (!$selectedItem) { + http_response_code(404); + return 'Ошибка 404. Страница, которую Вы ищете, не может быть найдена'; + } + return null; +} diff --git a/functions/toMySQL.php b/functions/toMySQL.php index 784053a..11ae13f 100644 --- a/functions/toMySQL.php +++ b/functions/toMySQL.php @@ -43,15 +43,18 @@ function currentCategories(mysqli $connect) * * @return array of selected item */ -function selectedItem(mysqli $connect, int $itemId) +function selectedItem(mysqli $connect, $itemId) { - $takeSelectedItem = "SELECT i.id, i.name, first_price, image, DATE_FORMAT(expiry_date, '%d.%m.%Y') " + if (!empty($itemId)) { + $takeSelectedItem = "SELECT i.id, i.name, first_price, image, DATE_FORMAT(expiry_date, '%d.%m.%Y') " . "as expiry_date, c.name as category, MAX(price) as price, step_bet, description " . "FROM items i " . "LEFT JOIN bets b ON b.item_id = i.id " . "JOIN categories c ON i.category_id = c.id " . "WHERE i.id = $itemId " . "GROUP BY i.id "; - $selectedItem = mysqli_query($connect, $takeSelectedItem); - return isExistResult($selectedItem)[0]; + $selectedItem = mysqli_query($connect, $takeSelectedItem); + return isExistResult($selectedItem); + } + return null; } diff --git a/lot.php b/lot.php index bfe0d99..ad9a839 100644 --- a/lot.php +++ b/lot.php @@ -10,18 +10,23 @@ $selectedItem = selectedItem($connect, $itemId); $currentCategories = currentCategories($connect); -$page_content = include_template( - 'lot.php', - [ - 'categories' => $currentCategories, - 'item' => $selectedItem - ] -); +$page_content = showErrorItemId($selectedItem); +$title = showErrorItemId($selectedItem); +if (empty($page_content)) { + $title = $selectedItem[0]['name']; + $page_content = include_template( + 'lot.php', + [ + 'categories' => $currentCategories, + 'item' => $selectedItem[0] + ] + ); +} $layout_content = include_template( 'layout.php', [ - 'title' => $selectedItem['name'], + 'title' => $title, 'is_auth' => $is_auth, 'user_name' => $user_name, 'content' => $page_content,