SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Paging on dynamic pages

    Hi all,

    Have managed to create pagination on static page(.html extension) using following script
    http://www.php-mysql-tutorial.com/wi...using-php.aspx

    But not able to implement same thing on dynamic page.

    Background - I have Archive section for news. When you click on that link I am grabbing ID of that month to display all results related to that ID. Doing that by rewriting in .htaccess file as
    RewriteRule ^archive-news/([0-9]*)/.* /archiveItempage.html?monthID=$1 [L]

    When you click on Archive link the page where you will go has url
    http://domainname.com/archive-news/3/March

    if I click on 2 page, nothing appears, as for second page url appears as a
    http://domainname.com/archiveItempage.html?page=2

    For script, pls check above mentioned link, Do i need to write another rule in htaccess file to get it working???
    Pls let me know what wrong I am doing? And how can I get it working???

    Regards
    Anaya

  2. #2
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so it looks like you need to get your pagination to link like this:

    http://domainname.com/archive-news/3/March/?page=2

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your reply.
    Yes you got it right. Url should appear as
    http://domainname.com/archive-news/3/March?page=2

    But because of using $self = $_SERVER['PHP_SELF'] and rewrite rule it takes archiveItempage.html in url.

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You should not use $_SERVER['PHP_SELF'] in your generation of the URLs, but write /archive-news/3/March yourself (from $_GET['monthID'] and wherever the 3 came from). mod_rewrite won't change the links you put in the pages, you have to change them to display the URLs you want.

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Dan,

    I think that was my misunderstanding about rewrite rules.

    Have written the following code for Archive link -
    Code:
    <a href="archiveItempage4.html/monthID=<?=$d->monthID?>/<?=$d->monthName?>"><?=$d->monthName?></a>
    And on ArchiveItempage4.html page,
    Code:
    $monthID = $_GET['monthID'];
     $monthID = mysql_real_escape_string($monthID); 
     $query = mysql_query("select * from Articles where MONTH(Date) = '$monthID' order by Date desc ");
    No rewrite rule for in .htaccess file.

    But there is an issue if I click on Archive link that goes to archiveItempage.html but no results appear on that page.
    That means its not considering $monthID = $_GET['monthID'];
    Link appaers as
    http://domainname/archiveItempage4.html/monthID=3/March

    Definately I am missing something. Pls let me know. I have self taught PHP myself!

    Regards
    Anaya.

  6. #6
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Finally managed to sort out the issue mentioned in above thread. Instead of using forward slash in above code, used question mark, so the code for link is now
    Code:
    <a href="archiveItempage4.html?monthID=<?=$d->monthID"><?=$d->monthName?></a>


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
  •