Hello to all. I am writing a site. There was a problem. I display a topic with page-by-page navigation, that is, there are, for example, 21 articles, there will be 5 articles per page, 5 pages will turn out, right? That's only when the articles end in DB, then it just cycles out the form -n number of times, that is, 1 article will print and 4 is simple, here's a picture . Here is the code for the article file.

    4 answers 4

    Let's initially use the search on the HashCode forum, which will immediately throw out one answer.

    Page navigation

    And more will use the search on the forum, and not duplicate questions. I think that this question can be closed or deleted.

      One question: why in the loop do you have the value of $ num, if you already know that the number of entries does not exceed it? Moreover, for some reason, when starting the values, you start the cycle ... Therefore:

      echo "<table>"; while ( $postrow = mysql_fetch_array($result)){ echo "<tr> <div class='face_m_hide'> <div class='face_pre'></div> <h2><span style='color: rgb(51, 51, 255);'><a href=''>Категория</a></span> - <a href='/post.php?id=".$postrow['id']."'>".$postrow['title']."</a></h2><br> <center><img style='' alt=''src='".$postrow['img']."'> <br> <script type='text/javascript' src='http://trollface.yaxakep.ru/share42.js'></script> <script type='text/javascript'>share42('http://trollface.yaxakep.ru/')</script> </center> <br> </div> \r\n"; // <-- этот кусок кода - просто пипец. оставим его на совести автора } echo "</table>"; 
      • the worst thing is that the author’s version is written in the examples on the same php.su Example php.su/articles/?cat=examples&page=062 - Ruslan Librovsky
      • one
        GK multiplies and multiplies. Special thanks for the lines while ($ postrow [] = mysql_fetch_array ($ result)) echo "<table>"; - ling
      • This is just pipets! - Artem

      In the while loop, you forgot "{}" , i.e. all echo you should have between curly brackets while loop

        Yes, yes, I also came across this solved the problem of stopping the cycle:

         for($i = 0; $i < $num; $i++) { if (empty($postrow[$i]['id'])) {break;} } 

        since $ num is set at the beginning of the script forcibly = 10 then the for loop will run 10 times ...
        I should work exactly this script and used in the project.

        • Yes, comrades, yes ... I sadly read what you write. > <$ num why run through the loop from 0 to 10 and not use the number of records that you pull out of the database? - Artem
        • Ruslan thank you! You helped a lot!) - Pavel Dura
        • This answer, in my opinion, is not relevant at all, and is wrong. I’m telling you a secret, this is where the govnod is born - Artem
        • I know wrong but it solves the problem. And how more rationally does the author of the question either decide either to use it or do it wisely ... - Ruslan Librovsky
        • This does not solve the problem, it only confuses. - Artem