Advertisement
markeze

Untitled

Oct 20th, 2022 (edited)
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 7.24 KB | None | 0 0
  1. <?php
  2. require_once('php/bd.php');
  3. require_once('php/function.php');
  4. if(!empty([$_GET['categories']]) or !empty($_GET['new']) or !empty($_GET['sale'])) {
  5.  $where = "";
  6.  if($_GET['categories']) {
  7.    $where = addWhere($where, "`categories` = '".htmlspecialchars($_GET["categories"])."'");
  8.  }
  9.  if($_GET['new']) {
  10.    $where = addWhere($where, "`new` = '1'");
  11.  }
  12.  if($_GET['sale']) {
  13.    $where = addWhere($where, "`sale` = '1'");
  14.  }
  15.  if($_GET['min-price'] or $_GET['max-price']) {
  16.    $where = addWhere($where, "`price` BETWEEN '".htmlspecialchars($_GET["min-price"])."' and '".htmlspecialchars($_GET["max-price"])."'");
  17.  }
  18.  if($_GET['sort']) {
  19.    $where .=  " ORDER BY price ".htmlspecialchars($_GET['sort']);
  20.  }
  21.  if ($where) {
  22.    $sql = "WHERE $where";
  23.  }
  24. }
  25. $query = $pdo->query("SELECT * FROM (SELECT ID FROM `tovaru` $sql) as ID, (SELECT MIN(`price`) as min_price, MAX(`price`) as max_price FROM `tovaru` $sql) as price");
  26. $price = $query->fetch(PDO::FETCH_ASSOC);
  27. $count = $query->rowCount();
  28. $kol = 9; // Количество записей на одну страницу
  29. ?>
  30.  
  31. <!DOCTYPE html>
  32. <html lang="ru">
  33. <head>
  34.   <meta charset="utf-8">
  35.   <title>Fashion</title>
  36.  
  37.   <meta name="description" content="Fashion - интернет-магазин">
  38.   <meta name="keywords" content="Fashion, интернет-магазин, одежда, аксессуары">
  39.  
  40.   <meta name="theme-color" content="#393939">
  41.  
  42.   <link rel="preload" href="img/intro/coats-2018.jpg" as="image">
  43.   <link rel="preload" href="fonts/opensans-400-normal.woff2" as="font">
  44.   <link rel="preload" href="fonts/roboto-400-normal.woff2" as="font">
  45.   <link rel="preload" href="fonts/roboto-700-normal.woff2" as="font">
  46.  
  47.   <link rel="icon" href="img/favicon.png">
  48.   <link rel="stylesheet" href="css/style.css">
  49.   <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  50.   <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  51.   <script src="js/scripts.js" defer=""></script>
  52. </head>
  53. <body>
  54. <header class="page-header">
  55.   <a class="page-header__logo" href="#">
  56.     <img src="img/logo.svg" alt="Fashion">
  57.   </a>
  58.   <nav class="page-header__menu">
  59.     <ul class="main-menu main-menu--header">
  60.       <li>
  61.         <a class="main-menu__item" href="#">Главная</a>
  62.       </li>
  63.       <li>
  64.         <a class="main-menu__item" href="#">Новинки</a>
  65.       </li>
  66.       <li>
  67.         <a class="main-menu__item active">Sale</a>
  68.       </li>
  69.       <li>
  70.         <a class="main-menu__item" href="delivery.html">Доставка</a>
  71.       </li>
  72.       <li>
  73.         <a class="main-menu__item" href="authorization.html">Кабинет</a>
  74.       </li>
  75.     </ul>
  76.   </nav>
  77. </header>
  78. <main class="shop-page">
  79.   <header class="intro">
  80.     <div class="intro__wrapper">
  81.       <h1 class=" intro__title">COATS</h1>
  82.       <p class="intro__info">Collection 2018</p>
  83.     </div>
  84.   </header>
  85.   <section class="shop container">
  86.     <section class="shop__filter filter">
  87.       <form> // ФОРМА
  88.           <div id="message"></div>
  89.           <div class="filter__wrapper">
  90.             <b class="filter__title">Категории</b>
  91.             <ul class="filter__list">
  92.               <?
  93.              if(isset($_GET['categories'])) {
  94.                ?><input class="categories" type="hidden" name="categories" value="<?=$_GET['categories']?>"><?
  95.              }
  96.              ?>
  97.               <li>
  98.                 <a class="filter__list-item <? if(!isset($_GET['categories'])) { echo 'active'; } ?>" href="index.php">Все</a>
  99.               </li>
  100.               <li>
  101.                 <a class="filter__list-item <? if($_GET['categories'] == 'girl') { echo 'active'; } ?>" href="?categories=girl">Женщины</a>
  102.               </li>
  103.               <li>
  104.                 <a class="filter__list-item <? if($_GET['categories'] == 'boy') { echo 'active'; } ?>" href="?categories=boy">Мужчины</a>
  105.               </li>
  106.               <li>
  107.                 <a class="filter__list-item <? if($_GET['categories'] == 'children') { echo 'active'; } ?>" href="?categories=children">Дети</a>
  108.               </li>
  109.               <li>
  110.                 <a class="filter__list-item <? if($_GET['categories'] == 'accessories') { echo 'active'; } ?>" href="?categories=accessories">Аксессуары</a>
  111.               </li>
  112.             </ul>
  113.           </div>
  114.         <div class="filter__wrapper">
  115.             <b class="filter__title">Фильтры</b>
  116.             <div class="filter__range range">
  117.               <span class="range__info">Цена</span>
  118.               <div class="filter_all range__line" aria-label="Range Line"></div>
  119.               <div class="range__res">
  120.                 <?
  121.                if(isset($_GET['min-price'])) {$min = htmlspecialchars($_GET['min-price']);} else {$min = $price['min_price'];}
  122.                if(isset($_GET['max-price'])) {$max = htmlspecialchars($_GET['max-price']);} else {$max = $price['max_price'];}
  123.                ?>
  124.                 <input type="hidden" name="min-price" id="min-price-hide" value="<?=$min?>">
  125.                 <input type="hidden" name="max-price" id="max-price-hide" value="<?=$max?>">
  126.                 <span class="range__res-item min-price"><?=$min?></span>
  127.                 <span class="range__res-item max-price"><?=$max?></span>
  128.               </div>
  129.             </div>
  130.           </div>
  131.          
  132.           <fieldset class="custom-form__group">
  133.             <input type="checkbox" name="new" value="1" class="filter_all new" <? if(isset($_GET['new'])) { echo 'checked'; } ?>>Новинки<br>
  134.             <input type="checkbox" name="sale" value="1" class="filter_all sale" <? if(isset($_GET['sale'])) { echo 'checked'; } ?>>Распродажа
  135.           </fieldset>
  136.           <button class="button" type="submit" style="width: 100%">Применить</button>
  137.       </form>
  138.     </section>
  139.     </form>
  140.     <div class="shop__wrapper">
  141.       <section class="shop__sorting">
  142.         <div class="shop__sorting-item custom-form__select-wrapper">
  143.           <select class="custom-form__select" name="category">
  144.             <option hidden="">Сортировка</option>
  145.             <option class="sort" value="ASC">От дешевых к дорогим</option>
  146.             <option class="sort" value="DESK">От дорогих к дешевым</option>
  147.           </select>
  148.         </div>
  149.         <p class="shop__sorting-res">Найдено <span class="res-sort"><?=$count?></span> моделей</p>
  150.       </section>
  151.       <section class="shop__list">
  152.         <?php
  153.        if (isset($_GET['page'])){
  154.          $page = $_GET['page'];
  155.        }
  156.        else  {
  157.            $page = 1;
  158.        }
  159.        $art = ($page * $kol) - $kol;
  160.        $query = $pdo->query("SELECT * FROM `tovaru` $sql LIMIT $art, $kol");
  161.         while($row = $query->fetch(PDO::FETCH_ASSOC)) {
  162.         ?>
  163.             <article class="shop__item product" tabindex="0">
  164.                 <div class="product__image">
  165.                 <img src="img/products/<?=$row['img']?>" alt="product-name">
  166.                 </div>
  167.                 <p class="product__name"><?=$row['name']?></p>
  168.                 <span class="product__price"><?=$row['price']?></span>
  169.             </article>
  170.         <?php
  171.        }
  172.        ?>
  173.       </section>
  174. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement