Answer the question
In order to leave comments, you need to log in
Unable to display variable?
I am newbie! I'm learning how to create an online store from a video tutorial. The task is to display a specific brand from the database by clicking on the buttons:
<button id="button_brand" >
<a id="button_brand2" href="view_goods_brand.php?cat='.strtolower($row["name"]).'">'.$row["name"].' посмотреть косметику </a></button>
<!DOCTYPE html>
<html >
<head>
<?php
include('includes/db.php');//Подключаю БД
$cat = $_GET["cat"];
$sorting = $_GET["sort"];
switch ($sorting) {
case 'price-asc';
$sorting = 'price ASC';
$sort_neme = 'От дешевых к дорогим';
break;
case 'price-desc';
$sorting = 'price DESC';
$sort_neme = 'От дорогих к дешевым';
break;
case 'popular';
$sorting = 'count DESC';
$sort_neme = 'Популярные';
break;
case 'news';
$sorting = 'datetime DESC';
$sort_neme = 'Новинки';
break;
case 'brand';
$sorting = 'brand DESC';
$sort_neme = 'Бренд';
break;
default:
$sorting = 'datetime DESC';
$sort_neme = 'Нет сортировки';
break;
}
?>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initil-scale=1"/> <!-- ДЛЯ МОБИЛЬНЫХ УСТРОЙСТВ -->
<link href="css/stil.css" rel="stylesheet" type="text/css"/> <!-- ССЫЛКА НА CSS -->
<link href="css/media.css" rel="stylesheet" type="text/css"/> <!-- ССЫЛКА НА CSS -->
<title>Косметика для лица</title><!-- Название веб-страницы -->
<?php require "header.php"; ?>
</head>
<div id="topbutton">↑<br/>Наверх</div>
<body>
<div id="conteiner">
<div id="conteiner-goods">
<div id="floatingBarsG">
<div class="blockG" id="rotateG_01"></div>
<div class="blockG" id="rotateG_02"></div>
<div class="blockG" id="rotateG_03"></div>
<div class="blockG" id="rotateG_04"></div>
<div class="blockG" id="rotateG_05"></div>
<div class="blockG" id="rotateG_06"></div>
<div class="blockG" id="rotateG_07"></div>
<div class="blockG" id="rotateG_08"></div>
</div>
<p id="view">Вид:</p>
<a href="#"> <img id="box_list1" src="image/nav/box-list.png" alt="img"/></a>
<a href="#"> <img id="box_list2" src="image/nav/box1.png" alt="img"/></a>
<p id="sort">Cортировать:</p>
<a id="link"><?php echo $sort_neme; ?></a>
<div id="sort_block">
<a href="for_face.php?sort=price-asc">От дешевых к дорогим</a><br>
<a href="for_face.php?sort=price-desc">От дорогих к дешевым</a><br>
<a href="for_face.php?sort=popular">Популярные</a><br>
<a href="for_face.php?sort=news">Новинки</a><br>
<a href="for_face.php?sort=brand">Бренд</a>
</div>
<div id="single_goods_block">
<?php
if (!empty($cat))
{
$querycat = "brand='$cat'";
}else{
if(!empty ($cat)){
$querycat='';
}
}
echo "Условие:"+$cat;
$result = mysqli_query($link, "SELECT * FROM teble_products $querycat ORDER BY $sorting");//выводим товары
if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_array($result);
do {
echo('
<div id="goods_block">
<img class="img_face" src="image/goods/fase/'.$row["image"].'"/>
<p class="style_title"><a href="#">' . $row["title"] . '</a> </p>
<hr>
<a data-tooltip="Просмотры"><img id="reviews" src="image/nav/eye.png"/><p id="reviews_quantity">0</p></a>
<a data-tooltip="Добавить в Избранные"><p id="heart_quantity">0</p> <img id="heart" src="image/nav/heart.png"/></a>
<p class="price_goods_face"><strong> '.$row["price"].' </strong> руб.</p>
<a href="http://korea.ru/cart.php" data-tooltip="Корзина">
<img id="cart_goods_face"src="image/Box pink-256.png" alt="img"/>
<p id="cart_quantity">0</p>
</a>
<div class="mini_description"> '.$row["mini_description"].'</div>
</div>
');
}
while ($row = mysqli_fetch_array($result));
}
?>
</div>
<div id="single_goods_line">
<?php
if (!empty($cat))
{
$querycat = "brand = '$cat'";
}
$result = mysqli_query($link, "SELECT * FROM teble_products $querycat ORDER BY $sorting");//выводим товары
if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_array($result);
do {
echo('
<div id="goods_block_line">
<img class="img_face_line" src="image/goods/fase/'.$row["image"].'"/>
<p class="style_title_line"><a href="#">' . $row["title"] . '</a> </p>
<a data-tooltip="Просмотры"><img id="reviews_line" src="image/nav/eye.png"/><p id="reviews_quantity_line">0</p></a>
<a data-tooltip="Добавить в Избранные"><p id="heart_quantity_line">0</p> <img id="heart_line" src="image/nav/heart.png"/></a>
<a href="http://korea.ru/cart.php" data-tooltip="Корзина">
<img id="cart_goods_face_line"src="image/Box pink-256.png" alt="img"/>
<p id="cart_quantity_line">0</p>
</a>
<p class="price_goods_face_line"><strong> '.$row["price"].' </strong> руб.</p>
<div class="description_line"> '.$row["description"].'</div>
</div>
');
}
while ($row = mysqli_fetch_array($result));
}
?>
</div>
</div>
</div>
<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script> <!-- подключается первым -->
<script type="text/javascript" src="js/goods.js"></script>
<script type="text/javascript" src="js/script.js"></script><!--подключается вторым-->
</body>
<?php include "footer.php"; ?>
</html>
Answer the question
In order to leave comments, you need to log in
Your sorting is done normally, but filtering through one place.
And for God's sake, throw out these video courses from Ruseller, they won't teach you anything normal, you'll become a kid.
<?php
if (!empty($cat))
{
$cat = mysqli_real_escape_string($link, $cat);
$querycat = "WHERE brand = '$cat'";
}
$result = mysqli_query($link, "SELECT * FROM teble_products $querycat ORDER BY $sorting");//выводим товары
while ($row = mysqli_fetch_array($result)) {
echo('
<div id="goods_block_line">
<img class="img_face_line" src="image/goods/fase/'.$row["image"].'"/>
');
}
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question