Next Link Prev Link

Discussion in 'PHP' started by kirpy, Feb 21, 2006.

  1. #1
    I have contents in db and all have id's title's and links.

    blah1.php
    blah2.php
    blah3.php
    ..........

    When viewing blah1.php i want to display a link for blah2.php and goes as in blah2.php a link for blah1.php and blah3.php as [next link- prev link]. Can you help please?
     
    kirpy, Feb 21, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you are generating the pages from a database you should be able to echo the id number of 2 if you are on blah2.php or 3 if you are on blah3.php to the screen.

    Then you simply do

    $nextpage=$currentpage+1;
    echo"<a href=\"blah$nextpage.php\">Next Page</a>";
    PHP:
     
    mad4, Feb 22, 2006 IP
  3. Lordo

    Lordo Well-Known Member

    Messages:
    2,082
    Likes Received:
    58
    Best Answers:
    0
    Trophy Points:
    190
    #3
    If that is not everything you need, then let us know.
     
    Lordo, Feb 22, 2006 IP
  4. kirpy

    kirpy Member

    Messages:
    61
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    48
    #4
    With that code which ever page i view it echos 1.php as "next page" link. Maybe it ll be better to give more details. I added id numbers, titles and page links to the db. So the row is like

    
    id title  link
    1 atitle atitle-is-atitle
    2 btitle btitle-is-btitle
    3 ctitle ctitle-is-ctitle
    4 dtitle dtitle-is-dtitle
    ..........
    
    Code (markup):
    I $_GET the id numbers of links from left menu and display on index page as <? echo '' .$result[title];?>. I want to print the next link on db there too.
     
    kirpy, Feb 22, 2006 IP
  5. mercerenator

    mercerenator Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    hi kirpy,

    i'm not sure if thats what u need, but... :

    if ($currentpageID >1) {
       $prevpageID = $currentpageID - 1;   
       echo"<a href=\"$prevpageID.php\">Prev Page</a>";
    }
    if ($currentpageID < count($pagecount)) {
          $nextpageID = $currentpageID + 1;
          echo"<a href=\"$nextpageID.php\">Next Page</a>";
    }
    
    PHP:
    hope it helps...
     
    mercerenator, Feb 22, 2006 IP
  6. kirpy

    kirpy Member

    Messages:
    61
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    48
    #6
    It doesn't echo anything mercerenator? Do i need to define somethings?
     
    kirpy, Feb 23, 2006 IP
  7. mercerenator

    mercerenator Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    kirpy, i only gave u concept;)

    to make it work u need to define in every blahX.php the $currentpageID, for example:
    in blah1.php add line
    $currentpageID = 1;
    PHP:
    in blah2.php
    $currentpageID = 2;
    PHP:
    and so on...

    moreover in every blahX.php $pagecount must be defined, so u need to get this variable from your db...
    with MySQL it would be something like:
    $link = mysql_connect ('server','user','pass');
    mysql_select_db('database', $link);
    
    $result = mysql_query('SELECT * FROM name_of_the_table_with_your_data', $link);
    $pagecount = mysql_num_rows($result); 
    PHP:
    and the rest of the code would stay as it was (except the count($pagecount) function, which in this case is unnesesary) :
          if ($currentpageID >1) {
             $prevpageID = $currentpageID - 1;   
             echo"<a href=\"$prevpageID.php\">Prev Page</a>";
          }
          if ($currentpageID < $pagecount) {
                $nextpageID = $currentpageID + 1;
                echo"<a href=\"$nextpageID.php\">Next Page</a>";
          } 
    
    PHP:
    heh its getting complicated, hope it helps ...or maybe i'm missing ur point?
     
    mercerenator, Feb 23, 2006 IP