[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Adding pagination to php page

Posted on 2015-01-22
2
Medium Priority
?
122 Views
Last Modified: 2015-01-30
Hi,
    I have a php page which polls a database and then creates a table based on the results, however I need to add pagination.  Ideally showing the page number, and also a dropdown to select the number of rows, something like 5, 10, 15 or 20 at a time?

This is my code so far:

<?php



$db="database";

$link = mysql_connect("localhost","user","pass");

if (! $link)

die("Couldn't connect to MySQL");



mysql_select_db($db)

or die("Couldn't open $db: ".mysql_error());


$searchdata = $_GET['field'];

$data = $_GET['DoID'];    

$resultall = mysql_query("SELECT * FROM maindata WHERE gpname LIKE '%".$_GET['field']."%' OR postcode LIKE '%".$_GET['field']."%' OR area LIKE '%".$_GET['field']."%' OR Do LIKE '%".$_GET['DoID']."%'")or die("SELECT Error: ".mysql_error());

$num_rows = mysql_num_rows($resultall);



?>



<html>



<head>

<meta http-equiv="Content-Language" content="en-gb">

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title>Search Results</title>

<style>
.whiteBackground { background-color: #9DC3E6; }
.grayBackground { background-color: #DBE8F6; }
</style>

</head>



<body>



<div align="center">

<br>

<font face="Arial" size="2" color="#CC0000"><a href="./">

<font color="#CC0000">Back to search option</font></a></font><br>



      &nbsp;<p><b><font face="Tahoma" size="6">Results</font></b></p>

      <p>&nbsp;</p>

      <div align="center">

      <br>

      <font face="arial" size="4" color="'FF0000"><strong><?php echo $num_rows; ?></strong> Results Returned</font><br><br>

<div align="center">

      <table border="0" width="1000" cellspacing="0" cellpadding="0">

            <tr>

                  <td width="23%" height="100" valign="top"><b><font face="Arial"><u>Practice Name</u></font></b></td>

                  <td width="5%" height="100" valign="bottom">

                  <p align="center"><font face="Arial" size="1">Tick to Compare</font></td>

                  <td width="18%" height="100" background="http://www.h.co.uk.co.uk/gpw-admin/images/filler1.png">

                  <b><font face="Arial">Booking &amp; </font></b>
                  <p><b><font face="Arial">Contact</font></b></td>

                  <td width="18%" height="100" background="http://gpwatch.healthwatchsandwell.co.uk/gpw-admin/images/filler2.png">&nbsp;</td>

                  <td width="18%" height="100" background="http://www.h.co.uk.co.uk/gpw-admin/images/filler3.png">&nbsp;</td>

                  <td width="18%" height="100" background="http://www.h.co.uk/gpw-admin/images/filler4.png">&nbsp;</td>



            </tr>

      </table>

</div><br><br>

<?php

 while ($rows1 = mysql_fetch_array($resultall)) {  

        $x++;

 $class = ($x%2 == 0)? 'whiteBackground': 'graybackground';

 ?>

          <div align="center">

      <table border="0" width="1000" cellspacing="0" cellpadding="0">

            <tr class=<?php echo $class; ?>>

                  <td width="23%" height="40"><b><font face="Arial" size="2">&nbsp;&nbsp;<?php echo $rows1['gpname']; ?></font></b></td>

            <td width="5%">

            <p align="center"><b><font face="Arial"><input type="checkbox" name="comparecheck" value="OFF"></font></b></td>

                  <td width="18%"><b><font face="Arial"><u></u></font></b></td>

                  <td width="18%"><b><font face="Arial"><u></u></font></b></td>

                  <td width="18%"><b><font face="Arial"><u></u></font></b></td>

                  <td width="18%"><b><font face="Arial"><u></u></font></b></td>

            </tr>

      </table>

</div>

  </div>

  <?php

  }

?>

</body>

</html>
0
Comment
Question by:damianb123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 33

Accepted Solution

by:
Big Monty earned 2000 total points
ID: 40564783
0
 

Author Closing Comment

by:damianb123
ID: 40580133
That was a great article, very easy to follow and pagination working a treat - thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question