#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Chennai,TamilNadu,India
    Posts
    33
    Rep Power
    14
    Hi Everybody
    I'm a newbie to PHP/MySQL. I'm having (for eg., 22 records) in my MySQL table. I want to display these 22 records into pages, each page contains 5 records. so 5 pages with each 5 records and the last page contains only 2 records, and Previous and Next links in each page.

    I've used LIMIT in select statement. But i dont know how to use this exactly.
    Cany anyone recommend me how to do this.

    Thanks in Advance
    Raghu.


    hogi
    Member posted August 28, 2000 07:49 AM
    --------------------------------------------------------------------------------
    I found this somewhere on this forum. GIve it a try:
    Found on August 25, 2000 09:30:00am off of DevShed
    ======================================================================================

    no problem, one thing i just noticed is that devshed has taken my escaped less than and greater than symbols for the previous and next links and turned them into actual less than an greater than symbols, something to keep in mind if you copy this
    also, sorry about the line break formatting, devshed seems to only allow one consecutive line break so unfortunately my code is all one line after another

    RyanP

    ======================================================================================

    //Cool example of record navigation in PHP:

    <?php
    // variables
    //--------------------------------------------------------------------------------------
    $limit = 10; // number of records to display
    $connect = "hostname, username, password"; // string to connect to database program
    $db = "databaseName"; // database to use
    $sql = "select * from tableName"; // string to query database
    //--------------------------------------------------------------------------------------

    $PATH_INFO = preg_replace("/^.*/([w.]+)$/", "1", $PATH_INFO);
    $offset = preg_replace("/D/", "", $offset);

    mysql_connect("$connect");
    mysql_select_db("$db");

    $result = mysql_query("$sql");
    $total = mysql_num_rows($result);

    if(!$offset)
    {
    $offset = 0;
    }
    elseif($offset >= $total)
    {
    $offset = $total - $limit;
    }

    $result = mysql_query("$sql limit $offset, $limit");

    while($data = mysql_fetch_array($result))
    {
    // output records
    //-----------------------
    print <<<EOF
    $data[fieldName1]

    <br>
    $data[fieldName2]

    <br>
    $data[fieldName3]

    <br><br>
    EOF;
    //-----------------------
    }

    // create link to previous page
    //---------------------------------------------------------------------
    if($offset <= 0)
    {
    $prevUrl = "<<";
    }
    elseif($offset < $limit && $offset > 0)
    {
    $prevUrl = "<a href="$PATH_INFO?offset=0"><<</a>";
    }
    else
    {
    $prev = $offset - $limit;
    $prevUrl = "<a href="$PATH_INFO?offset=$prev"><<</a>";
    }
    //---------------------------------------------------------------------

    // create link to next page
    //--------------------------------------------------------------------
    $next = $offset + $limit;

    if($next >= $total)
    {
    $nextUrl = ">>";
    }
    else
    {
    $nextUrl = "<a href="$PATH_INFO?offset=$next">>></a>";
    }
    //--------------------------------------------------------------------

    print "<br><br>$prevUrl ";

    // print page links
    //------------------------------------------------------------------------------------
    $numberOfPages = ceil($total / $limit);

    for($i=0; $i<$numberOfPages; $i++)
    {
    if($i * $limit == $offset)
    {
    print ($i + 1)." ";
    }
    else
    {
    print "<a href="$PATH_INFO?offset=".($i * $limit)."">".($i + 1)."</a> ";
    }
    }
    //------------------------------------------------------------------------------------

    print $nextUrl;
    ?>

    --------------------------------------------------------------------------------------

    Can Anyone Help me.
    The Code which has given by Yogi is working properly if i send the parameter of datatype varchar, between pages. I've tried to send date as the parameter. I'm getting that date in the address bar in the browser as http://www.xyz.com?postdate=02-10-2000&offset=10

    But the records in the second page are not displayed. When i tried to display $postdate it is displaying only --. the date 02, month 10, year 2000 are of being null. I dont know why it is taking as null.

    If i use the parameter as varchar datatype for eg. name and i'm sending as http://www.xyz.com?name=raghuramb&offset=10

    and tried to print the name, i'm getting displayed raghuramb in the page and search also works fine.

    Help Needed.

    TA
    Raghu.



  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Raghu,

    you may want to use urlencode() function for passing data via your url..

    <?
    $date="02-10-2000";

    echo "http://www.xyz.com?postdate=".urlencode($date)."&offset=10";
    //print the url...
    ?>

    and in your next page use urldecode() function to decode your encoded string for further use...

    see manual for details...




    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."

Similar Threads

  1. combing three pages into one
    By thindery in forum PHP Development
    Replies: 1
    Last Post: February 14th, 2004, 05:07 PM
  2. How to display two pages from one click
    By gajen in forum PHP Development
    Replies: 1
    Last Post: February 13th, 2004, 03:01 PM
  3. Dynamic display of unknown # of db records...?
    By mikeyguitar in forum Flash Help
    Replies: 0
    Last Post: February 10th, 2004, 10:14 PM
  4. how to display all the records in the database(mySQL)
    By icepricessa in forum PHP Development
    Replies: 2
    Last Post: February 8th, 2004, 06:59 PM
  5. split to multiple pages
    By c12052 in forum MySQL Help
    Replies: 0
    Last Post: January 25th, 2004, 04:40 PM

IMN logo majestic logo threadwatch logo seochat tools logo