Database Articles

  Home arrow Database Articles arrow Page 5 - PHP - Previous and Next Links
DATABASE ARTICLES

PHP - Previous and Next Links
By: Matt Wade
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 12
    2002-02-04

    Table of Contents:
  • PHP - Previous and Next Links
  • The LIMIT Clause
  • Starting Off with $start
  • Building the Previous and Next Links
  • Putting It All Together

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    PHP - Previous and Next Links - Putting It All Together


    (Page 5 of 5 )

    Ok, now that we have all the parts that we need, let's put them all together!

    <?php
    if(!isset($start)) $start 0;

    $query "SELECT * FROM table LIMIT " $start ", 10";
    //do database connection
    $result mysql_query($query); //you should do error checking
    //display data

    //this code was wrong, I did not have the second query. Thanks to Plaggy Pig.
    // need another query to get the total amount of rows in our table
    $query "SELECT count(*) as count FROM table"
    $result mysql_query($query);
    $row mysql_fetch_array($result);
    $numrows $row['count'];
    if(
    $start &gt0
       echo 
    "&lt;a href=\"" $PHP_SELF "?start=" . ($start 10) . 
            
    "\"&gt;Previous&lt;/a&gt;&lt;BR&gt;\n";
    if(
    $numrows > ($start 10)) 
       echo 
    "&lt;a href=\"" $PHP_SELF "?start=" . ($start 10) . 
            
    "\"&gt;Next&lt;/a&gt;&lt;BR&gt;\n";
    ?>

    Man is that simple stuff or what? Of course, there is a lot you can do with this other than what I have shown. But, this should get you well on your way to displaying Previous and Next links on your website.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.
    blog comments powered by Disqus

    DATABASE ARTICLES ARTICLES

    - Completing a Book Inventory Management System
    - Uploading Images for a Book Inventory Manage...
    - Finishing the Add Book Story for a Book Inve...
    - Integration Testing for a Book Inventory Man...
    - User Stories for a Book Inventory Management...
    - Unit Testing a Book Inventory Management Sys...
    - Testing a Book Inventory Management System
    - Implementing Models for a Book Inventory Man...
    - Book Inventory Application: Publishers and B...
    - Handling Publishers in a Book Inventory Mana...
    - Publisher Administration for Book Inventory ...
    - Book Inventory Management
    - Using the SQL Reference Manual
    - Using Oracle SQL Developer with SQL Statemen...
    - Fixing Errors with Oracle SQL Developer


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap