here is the php function for content and pagination output:

define("PER_PAGE",15); $page = (!isset($_GET['page'])) ? $page='0' : $page=$_GET['page']; $page = $_GET['page']; $page = $page*PER_PAGE; function preview($sql,$res,$nums){ global $page; $num = ceil($nums/PER_PAGE); $sql .= "LIMIT ".$page.",".PER_PAGE.""; $newRes = mysql_query($sql); if($newRes){ if($row=mysql_num_rows($newRes)>0){ while ($resources = mysql_fetch_array($newRes)){ echo '<div class="block">'; echo '<a href="resource.php?id='.$resources['resources_id'].'"><h3>'.$resources['title'].'</h3></a>'; $string = substr($resources['description'], 0, 300); $string = rtrim($string, "!,.-"); echo '<h4>'.$string.'</h4>'; echo '<h5>'.'Категория : '.$resources['categories'].'</h5>'; $author = $resources["surname"]." ".mb_substr($resources["name"],0,1,'UTF-8').".".mb_substr($resources["middlename"],0,1,'UTF-8')."."; echo '<h5>'.'Автор : '.$author.'</h5>'; echo '</div>'; }; // КОД пагинации for($i=1;$i<=$num;$i++){ echo "<a class='pages' href='lib.php?categories=".$_GET['categories']."&page=".$i."'>".$i."</a> "; } // КОД пагинации }else{ echo "<p class='errmsg'>По Вашему запросу ничего не найдено!</p>"; } } } 

here is the php function for the query.

 function spec(){ $sql = "SELECT * FROM resources LEFT JOIN users ON users.id=resources.author_id LEFT JOIN categories ON categories.categories_id=resources.categories_id LEFT JOIN specialty ON specialty.specialty_id=resources.specialty_id WHERE categories.categories LIKE '%$_GET[categories]%' AND specialty.specialty LIKE '%$_POST[specialty]%' "; preview($sql); } 

here is the php function for the search button.

  function resources() { $cat=$_GET['categories']; $spec=$_POST['specialty']; $key=$_POST['key']; $search=$_POST['search']; if (isset($_POST['submit'])) { if($spec=="Выберите специальность" and ( empty($search) )){ echo "<p class='errmsg'>Что ищем? или Выберите специальность</p>"; }elseif($key=="author" and $spec!="Выберите специальность" and !empty($search)){ fullSearch(); }else if($key=="all"){ if($spec!="Выберите специальность" or ( !empty($search) )){ if(empty($search)){ spec(); }else if($spec=="Выберите специальность"){ search(); }else if($spec!="Выберите специальность" and !empty($search) ){ specSearch(); } } }else if($key!="all" and $key!="author"){ keySearch($key); }else if($key!="all" and $key=="author"){ search(); } } } 

Problem:

  Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\OpenServer\domains\apk-lib\functions.php on line 337 

on this line is

  $nums = mysql_num_rows($res); 
  • Instead of running the query, type die($sql); and see what's wrong with you - vp_arth
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

The first error is the assignment of a variable value through if, line 2:

 $page = (!isset($_GET['page'])) ? '0' : $_GET['page']; 

Line 2 does not make sense.

You form a request - add a space before limit, with this style of writing the request, sticking of the lines is not excluded. Remove. "" At the end of the request.

 $sql .= "LIMIT ".$page.",".PER_PAGE.""; 

You can not do it this way:

 if($row=mysql_num_rows($newRes)>0){ 
  • When doing this code-review instead of answering a question, ask yourself why the very first page is displayed? It seems to me that everything except the absence of a space before the limit is irrelevant to the question. - vp_arth
  • Is that all that confuses you in the code? - Kirill Korushkin
  • Not to embarrassment here) Just what is the point of making every line of this most refined sample in response? - vp_arth
  • Yes, I was the same, really a long time. Sometimes even now it happens so blunted that before the nails in the train .. e) It can be seen - it is learning. It's a pity ( - Kirill Korushkin