<?php
$link = mysqli_connect($db_host, $db_user, $db_password, $db_database)
or die("Ошибка " . mysqli_error($link));
if(!empty($cat))
{
$escaped_cat = mysqli_real_escape_string($link, $cat);
$where = "WHERE `brand` = '$escaped_cat'";
}
else
{
$where = '';
}
if (!empty($cat))
{
$catlink = "cat=$cat&";
}else
{
$catlink = "";
}
$num = 2; // Здесь указываем сколько хотим выводить товаров.
$page = (int)$_GET['page'];
if (!$where){
$count = mysqli_query($link, "SELECT COUNT(*) FROM `uploads_hudkow` $where ");
$temp = mysqli_fetch_array($count);
}else $temp='';
If ($temp[0] > 0)
{
$tempcount =$temp[0];
// Находим общее число страниц
$total = (($tempcount - 1) / $num) + 1;
$total = intval($total);
$page = intval($page);
if(empty($page) or $page < 0) $page = 1;
if($page > $total) $page = $total;
// Вычисляем начиная с какого номера
// следует выводить товары
$start = $page * $num - $num;
$qury_start_num = " $where LIMIT $start, $num";
} else {
$qury_start_num = " $where";
$page=1;}
$query = "SELECT * FROM `uploads_hudkow` $qury_start_num ";
$result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
if (mysqli_num_rows($result) > 0)
{
$row = mysqli_fetch_array($result);
do
{
$img_pathh = './uploads_images/'.$row["image"];
list($width, $height) = getimagesize($img_pathh);
$ratioh = $max_height/$height;
$ratiow = $max_width/$width;
$ratio = min($ratioh, $ratiow);
$width = intval($ratio*$width);
$height = intval($ratio*$height);
echo '
<div class="col-md-6 gallary">
<a data-fancybox="gallery" href="'.$img_pathh.'">
<img class="img-fluid img-gallery" src="'.$img_pathh.'" alt="...">
</a>
</div>
';
echo $temp;
}
while ($row = mysqli_fetch_array($result));
}
?>