Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pagination Error (Need Assistance)

    Hiya Guys,

    I'm using the following code to dynamically create pages if total records in a database reach over 8.

    Only if nothing is in the database, then "Next Screen" button is still clickable, taking you to another page. How do I disable the "Next Screen" button if nothing is in the database, and display a error message saying so?

    Also, if the records in the database equal the quantity to display per page, the "Next Screen" button is still clickable, taking the user to another page. How do I disable the "Next Screen" button if the records in the database equal the quantity to display per page?

    Code:
    <link rel="stylesheet" type="text/css" href="Index.css" />
    
    <?php
    $con = mysql_connect("localhost","peter","abc123");
    if (!$con)
    {
      die('Could not connect: ' . mysql_error());
    }
    
    mysql_select_db("TS", $con);
    
    $perpage = 8;
    
    $start = (isset($_GET['id'])) ? $_GET['id'] : 0;
    
    $TotalRec = mysql_result(mysql_query("SELECT COUNT(*) FROM Buttons"), 0); 
    
    $select = "SELECT * FROM Buttons LIMIT $start, $perpage";
    $result = mysql_query($select) or die(mysql_error());
    
    echo '<div id="Bar"></div>';
    echo '<div id="Container">';
    
    # Dislay your rows here in the loop
    while($row = mysql_fetch_array($result))
    {
      echo '<div class="But">';
      echo   '<img id="ButImg" src="ButImg.bmp">';
      echo   '<div id="ButTitle">' . $row['Title'] . '</div>';
      echo   '<div id="ButBody">' . $row['Description'] . '</div>';
      echo   '<img id="But_tl" src="But_tl.gif">';
      echo   '<img id="But_tr" src="But_tr.gif">';
      echo   '<img id="But_bl" src="But_bl.gif">';
      echo   '<img id="But_br" src="But_br.gif">';
      echo '</div>';
    }
    
    if($start == 0)
    {
      echo '<div id="ButPrevDis">';
      echo   '<div id="NavDis">Previous Screen</div>';
      echo '</div>';
    }
    else
    {
      echo '<div id="ButPrevEna">';
      echo   "<a href=\"./Display.php?id=" . ($start - $perpage) . "\" class=\"NavEna\">Previous Screen</a>";
      echo '</div>';
    }
    
    $page = ($_GET['id'] / $perpage) + 1;
    $total = ceil($TotalRec / $perpage);
    
    echo '<div id="Pag">';
    echo   '<div id="PagCap">' . $page . " of " . $total . '</div>';
    echo   '<img id="Pag_tl" src="Pag_tl.gif">';
    echo   '<img id="Pag_tr" src="Pag_tr.gif">';
    echo   '<img id="Pag_bl" src="Pag_bl.gif">';
    echo   '<img id="Pag_br" src="Pag_br.gif">';
    echo '</div>';
    
    if($start == $TotalRec - 1)
    {
      echo '<div id="ButNextDis">';
      echo   '<div id="NavDis">Next Screen</div>';
      echo '</div>';
    }
    else
    {
      echo '<div id="ButNextEna">';
      echo   "<a href=\"./Display.php?id=" . ($start + $perpage) . "\" class=\"NavEna\">Next Screen</a>";
      echo '</div>';
    }
    
    echo '</div>';
    ?>
    Any help would be grateful, as this is driving me nuts!!!
    Many Thanks, in advance!

    Salchester.
    The Future Is Here - Are You Ready?

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Using mysql_num_rows() will return the number of rows that where found matching the query.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •