SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I paginate my searched results here?

    I've got a mysql database with a table having 3 columns "fname,lname & phone" I have created a search script which perfectly works but what I want is display only 2 data as in 2 rows per page from the 'users' table in the respected order! I've got around 8 rows, so there should be 4 pages with next & prev buttons! How do I do it?

    here is my html form
    Code HTML4Strict:
    <html>
        <head>
            <title>Search the Database</title>
        </head>
     
        <body>
     
        <form action="search4.php" method="post">
         Search: <input type="text" name="term" /><br />
        <input type="submit" name="submit" value="Submit" />
        </form>
     
        </body>
    </html>

    & here is search4.php


    Code PHP:
    <?php
     
    mysql_connect ("localhost", "root","")  or die (mysql_error());
    mysql_select_db ("mydata");
     
     $term = $_POST['term'];
     
    $sql = mysql_query("select * from users where fname like '%$term%'");
     
    while ($row = mysql_fetch_array($sql)){
     
        echo '<br/> First Name: '.$row['fname'];
        echo '<br/> Last Name: '.$row['lname'];
        echo '<br/> Phone: '.$row['phone'];
        echo '<br/><br/>';
        }
     
    ?>

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    You might want to google for 'pagination', or do a search for it in this forum. There are lots of threads about it.


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
  •