Results 1 to 5 of 5

Thread: Problem of pagination

  1. #1
    Join Date
    May 2008
    Posts
    962

    Problem of pagination

    I wrote a php script to display per page news. Finally in theory because in practice it is the last news that appears on all my pages. It's several days that I try but in vain. I think my code is completely wrong, but will know.

    Here is my code:
    PHP Code:
      <?php 
      mysql_connect 
    "localhost""********""**********"); 
      
    mysql_select_db ("**********"); 
      
    $numberofmessagesperpage ;
      
    $return mysql_query ('SELECT COUNT (*) AS nb_messages FROM news'); 
      
    $data mysql_fetch_array ($return); 
      
    $numberofpages $data ['nb_messages']; 
      if (isset (
    $_GET ['page']) && is_int ($_GET ['page']) && $_GET ['page']> && $_GET 'Page'] <$numberofpages
      
    $Page $_GET ['page'] - 1
      else 
      
    $Page 0
      
    $return mysql_query ('SELECT * FROM news ORDER BY id DESC LIMIT'$Page.', 1'); 
      while (
    $data mysql_fetch_array ($return)) 
      {
      echo 
      
    '</p> 
      <div class="news"> 
      <h3>. $Data ['
    title']. " 
      <em> the '
    date ('d/m/Y to HHI'$data [timestamp']).' </em
      </
    H3
      <
    p'; 
      $content = nl2br (stripslashes ($data ['
    content'])); 
      echo $content. '
    </p> </div>'; 
      }
      echo '
    Page:'; 
      for ($i = 1; $i <= $numberofpages; $i++) 
      {
      echo '
    <a href="index.php?page='. $i.'">'. $i. '</a>'; 
      }
      ?>


    If you have an idea of what will not, it would be nice to me to share your ideas

  2. #2
    Join Date
    May 2008
    Posts
    271

    Re: Problem of pagination

    Well firstly, in your condition, you:
    PHP Code:
    is_int ($_GET ['page']) 
    Even if $_GET ['page'] is a number it is not considered as integer by PHP so this test will fail whatever happens. So always be worth $Page 0.

    But anyway: Most of your code is useless. In fact, you can directly use WHERE to get your page without using COUNT, LIMIT and ORDER BY ... :

    PHP Code:
      SELECT FROM news WHERE id $Page 
    Finally, you does not escape your data to HTML output. If this is not done on purpose, there is a security hole if not done on purpose, I think it's a bad idea to use htmlspecialchariser data recording.

  3. #3
    Join Date
    May 2008
    Posts
    962

    Re: Problem of pagination

    Thank you for the info

    In fact, most of my script was made from a tutorial on the site. I don't have much control over php. It was already a good start, knowing that I learned HTML and CSS from another site.

    I will try to find other examples of news and re tweak my code.

  4. #4
    Join Date
    May 2008
    Posts
    271

    Re: Problem of pagination

    yes HTML and CSS is good because it does not much rigor in contrast to programming languages ...

  5. #5
    Join Date
    May 2008
    Posts
    685

    Re: Problem of pagination

    php generates html (even css). So I see no where is the problem. Simply that your class is defined in the css related to your html page

Similar Threads

  1. how can developper plugin the pagination with zend framework
    By manjava in forum Technology & Internet
    Replies: 1
    Last Post: 20-05-2011, 12:22 AM
  2. Sony VGNCS3 laptop 15 inch screen problem...LCD or CHIP problem?
    By Mick$Tyler in forum Hardware Peripherals
    Replies: 5
    Last Post: 31-10-2010, 06:49 AM
  3. Replies: 6
    Last Post: 27-07-2010, 12:10 AM
  4. hard disk problem, clicking sound and windows problem
    By rajat_2589 in forum Hardware Peripherals
    Replies: 1
    Last Post: 16-06-2010, 11:34 PM
  5. Replies: 4
    Last Post: 10-04-2010, 04:19 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,485,096.09365 seconds with 16 queries