L
L
lesmanora2020-05-08 17:38:52
PHP
lesmanora, 2020-05-08 17:38:52

Why is it not displaying the required number of products?

Doesn't display the number of products (num = 2 ) , what could be wrong?

spoiler
<?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));
}							
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
ninja op op, 2020-05-08
@kur4chyt

Try replacing if (!$where){
with
if(!empty($where)){

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question