spoiler<?php
include("include/db_connect.php");
include("functions/functions.php");
session_start();
include("include/auth_cookie.php");
$go = clear_string($_GET["go"]);
switch ($go) {
case "tshirt":
$query_aystopper= " WHERE visible = '1' AND Type = '1'";
$name_aystopper = "Футболки";
break;
case "sweatshirts":
$query_aystopper= " WHERE visible = '1' AND Type = '2'";
$name_aystopper = "Толстовки";
break;
case "trousers":
$query_aystopper= " WHERE visible = '1' AND Type = '3'";
$name_aystopper = "Брюки";
break;
case "mousepad":
$query_aystopper= " WHERE visible = '1' AND Type = '4'";
$name_aystopper = "Коврики";
break;
case "pendant":
$query_aystopper= " WHERE visible = '1' AND Type = '5'";
$name_aystopper = "Брелки";
break;
case "glass":
$query_aystopper= " WHERE visible = '1' AND Type = '6'";
$name_aystopper = "Кружки";
break;
case "phonecovers":
$query_aystopper= " WHERE visible = '1' AND Type = '7'";
$name_aystopper = "Чехлы";
break;
default:
$query_aystopper = "";
break;
}
$sorting = $_GET["sort"];
switch ($sorting){
case 'price-asc';
$sorting = 'price ASC';
$sort_name = 'От дешевых к дорогим';
break;
case 'price-desc';
$sorting = 'price DESC';
$sort_name = 'От дорогих к дешевым';
break;
case 'popular';
$sorting = 'count DESC';
$sort_name = 'Популярное';
break;
case 'news';
$sorting = 'datetime DESC';
$sort_name = 'Новинки';
break;
case 'title';
$sorting = 'title';
$sort_name = 'От А до Я';
break;
default:
$sorting = 'products_id DESC';
$sort_name = 'Нет сортировки';
break;
}
?>
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link href="css/reset.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="/js/jquery-migrate-1.4.1.min.js"></script>
<script type="text/javascript" src="/js/shop-script.js"></script>
<script type="text/javascript" src="/js/jquery.cookie.min.js"></script>
<script type="text/javascript" src="/js/jquery.form.js"></script>
<script type="text/javascript" src="/js/jquery.validate.js"></script>
<script type="text/javascript" src="/js/TextChange.js"></script>
<title>Сувениры и игровая аттрибутика из CSGO</title>
</head>
<body>
<div id="block-line"></div>
<div id="block-body">
<?php
include("include/block-header.php");
?>
<?php
include("include/top-menu.php");
?>
<div id="block-content">
<div id="block-sorting">
<p id="nav-breadcrumbs"><a href="index.php">Главная страница</a> \ <span>Все товары</span></p>
<ul id="options-list">
<li>Вид:</li>
<li><img id="style-grid" src="/images/icon-grid.png"/></li>
<li><img id="style-list" src="/images/icon-list.png"/></li>
<li>Сортировать:</li>
<li><a id="select-sort"><?php echo $sort_name ?></a>
<ul id="sorting-list">
<li><a href="index.php?sort=price-asc">От дешевых к дорогим</a></li>
<li><a href="index.php?sort=price-desc">От дорогих к дешевым</a></li>
<li><a href="index.php?sort=popular">Популярное</a></li>
<li><a href="index.php?sort=news">Новинки</a></li>
<li><a href="index.php?sort=title">От А до Я</a></li>
</ul>
</li>
</ul>
</div>
<ul id="block-tovar-grid">
<?php
$num = 6; // Количество товаров на вывод
$page = (int)$_GET['page'];
$count = mysql_query("SELECT COUNT(*) FROM table_products $query_aystopper",$link);
$temp = mysql_fetch_array($count);
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 = " LIMIT $start, $num";
}
$result = mysql_query("SELECT * FROM table_products $query_aystopper ORDER BY $sorting $qury_start_num",$link);
if (mysql_num_rows($result) > 0 )
{
$row = mysql_fetch_array($result);
do
{
if ($row["image"] != "" && file_exists("./uploads_images/".$row["image"]))
{
$img_path = './uploads_images/'.$row["image"];
$max_width = 200;
$max_height = 200;
list($width, $height) = getimagesize($img_path);
$ratioh = $max_height/$height;
$ratiow = $max_width/$width;
$ratio = min($ratioh, $ratiow);
$width = intval($ratio*$width);
$height = intval($ratio*$height);
}else
{
$img_path = "/images/no_images.png";
$width = 110;
$height = 200;
}
echo '
<li>
<div class="block-images-grid">
<img src="'.$img_path.'" width ="'.$width.'" height = "'.$height.'" />
</div>
<p class="style-title-grid"> <a href="">'.$row["title"].'</a></p>
<ul class="reviews-and-counts-grid">
<li><img src="/images/eye-icon.png" /><p>0</p></li>
<li><img src="/images/comment-icon.png" /><p>0</p></li>
</ul>
<a class="add-cart-style-grid"></a>
<p class="style-price-grid"><strong>'.$row["price"].'</strong> руб.</p>
<div class="mini-features">
'.$row["mini_features"].'
</div>
</li>
';
}
while ($row = mysql_fetch_array($result));
}
?>
</ul>
<ul id="block-tovar-list">
<?PHP
$result = mysql_query("SELECT * FROM table_products WHERE $query_aystopper ORDER BY $sorting $qury_start_num",$link);
if (mysql_num_rows($result) > 0 )
{
$row = mysql_fetch_array($result);
do
{
if ($row["image"] != "" && file_exists("./uploads_images/".$row["image"]))
{
$img_path = './uploads_images/'.$row["image"];
$max_width = 150;
$max_height = 150;
list($width, $height) = getimagesize($img_path);
$ratioh = $max_height/$height;
$ratiow = $max_width/$width;
$ratio = min($ratioh, $ratiow);
$width = intval($ratio*$width);
$height = intval($ratio*$height);
}else
{
$img_path = "/images/noimages80x70.png";
$width = 80;
$height = 70;
}
echo '
<li>
<div class="block-images-list">
<img src="'.$img_path.'" width ="'.$width.'" height = "'.$height.'" />
</div>
<ul class="reviews-and-counts-list">
<li><img src="/images/eye-icon.png" /><p>0</p></li>
<li><img src="/images/comment-icon.png" /><p>0</p></li>
</ul>
<p class="style-title-list"> <a href="">'.$row["title"].'</a></p>
<a class="add-cart-style-list"></a>
<p class="style-price-list"><strong>'.$row["price"].'</strong> руб.</p>
<div class="style-text-list">
'.$row["mini_description"].'
</div>
</li>
';
}
while ($row = mysql_fetch_array($result));
}
echo '</ul>';
if ($page != 1){ $pstr_prev = '<li><a class="pstr-prev" href="index.php?page='.($page - 1).'"><</a></li>';}
if ($page != $total) $pstr_next = '<li><a class="pstr-next" href="index.php?page='.($page + 1).'">></a></li>';
// Формируем ссылки со страницами
if($page - 5 > 0) $page5left = '<li><a href="index.php?page='.($page - 5).'">'.($page - 5).'</a></li>';
if($page - 4 > 0) $page4left = '<li><a href="index.php?page='.($page - 4).'">'.($page - 4).'</a></li>';
if($page - 3 > 0) $page3left = '<li><a href="index.php?page='.($page - 3).'">'.($page - 3).'</a></li>';
if($page - 2 > 0) $page2left = '<li><a href="index.php?page='.($page - 2).'">'.($page - 2).'</a></li>';
if($page - 1 > 0) $page1left = '<li><a href="index.php?page='.($page - 1).'">'.($page - 1).'</a></li>';
if($page + 5 <= $total) $page5right = '<li><a href="index.php?page='.($page + 5).'">'.($page + 5).'</a></li>';
if($page + 4 <= $total) $page4right = '<li><a href="index.php?page='.($page + 4).'">'.($page + 4).'</a></li>';
if($page + 3 <= $total) $page3right = '<li><a href="index.php?page='.($page + 3).'">'.($page + 3).'</a></li>';
if($page + 2 <= $total) $page2right = '<li><a href="index.php?page='.($page + 2).'">'.($page + 2).'</a></li>';
if($page + 1 <= $total) $page1right = '<li><a href="index.php?page='.($page + 1).'">'.($page + 1).'</a></li>';
if ($page+5 < $total)
{
$strtotal = '<li><p class="nav-point">...</p></li><li><a href="index.php?page='.$total.'">'.$total.'</a></li>';
}else
{
$strtotal = "";
}
if ($total > 1)
{
echo '
<div class="pstrnav">
<ul>
';
echo $pstr_prev.$page5left.$page4left.$page3left.$page2left.$page1left."<li><a class='pstr-active' href='index.php?page=".$page."'>".$page."</a></li>".$page1right.$page2right.$page3right.$page4right.$page5right.$strtotal.$pstr_next;
echo '
</ul>
</div>
';
}
?>
</div>
<?php
include("include/block-footer.php");
?>
</ul>
</div>
</body>
</html>
Собственно хотел сделать вывод товаров из бд по категориям. Нашел видеоурок, где парень делал вывод популярного\распродаж и т.д., просто переделал его запрос под свой, но вот незадача, начало выдавать ошибку.
(Warning
: mysql_num_rows() expects parameter 1 to be resource, boolean given in
D:\OpenServer\OSPanel\domains\localhost\view_aystopper.php
on line
221)
221 строчка - if (mysql_num_rows($result) > 0 )