SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Non-Member
    Join Date
    Jun 2007
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pagination Links

    Hi Folks,

    How do I adapt the following code, so that the data outputted (Title & Description) navigates to a different page upon being clicked?
    How do I store the linked page in the database?

    Code:
    <?php
    mysql_connect("localhost","peter","abc123");
        mysql_select_db("TS");
        
        $perpage = 2;
        
        $start = (isset($_GET['id'])) ? $_GET['id'] : 0;
        
        $TotalRec = mysql_num_rows(mysql_query("SELECT * FROM Buttons"));
        
        $select = "SELECT * FROM Buttons LIMIT $start, $perpage";
        $result = mysql_query($select) or die(mysql_error());
        
        # Dislay your rows here in the loop
        while($rows = mysql_fetch_array($result)){
            echo $rows['title'] . "=" . $rows['description'] . "<br>";
        }
        echo "<br><br>";
        
        if($start == 0){
            echo "Previous &laquo;";
        }else{
            echo "<a href=\"./Display.php?id=" . ($start - $perpage) . "\">Previous &laquo;</a>";
        }
        
        echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        
        if($start == $TotalRec - 1){
            echo "Next &raquo;";
        }else{
            echo "<a href=\"./Display.php?id=" . ($start + $perpage) . "\">Next &raquo;</a>";
        } 
    
    ?>

  2. #2
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does the Buttons table have an auto-increment ID field? If so, you could use the row ID in the query path. Then the script it links to could just look that row up by ID.

  3. #3
    Non-Member
    Join Date
    Jun 2007
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pagination Links

    How do I do that?
    What needs to be changed?

  4. #4
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure what you want them to link to. If it's another page in the same resultset, try:

    PHP Code:
    echo "<a href=\"./Display.php?id=" $rows['id'] . "\">" $rows['title'] . "=" $rows['description'] . "</a><br>"

  5. #5
    Non-Member
    Join Date
    Jun 2007
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It will be another page altogether

  6. #6
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Salchester View Post
    It will be another page altogether
    If the other page bears no obvious relationship to the paginated results, you should probably put the URL for that page in the database as well, then echo $row['url'] for the link href.


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
  •