PHP script to display MySQL Query results page by page?

  • Thread starter Thread starter Cathy V
  • Start date Start date
C

Cathy V

Guest
I want to write a php script that displays 10 results per page and allow user to navigate through the resul pages.

$data=mysql_query("SELECT * FROM tablename ")

//number of results(rows)

$rows=mysql_num_rows()

//number of pages

$pages=$rows/10
if $rows % 10!=0, $pages=$pages+1

//the php script( I want it as simple as possible)

with this layout, what script should i write to generate a navigation menu to display number of pages
- page 1( link "1") showing results LIMIT 0 10;
-page 2( link "2") showing results LIMIt 10 10;
-page 3 ( link "3")showing results LIMIT 20 10 etc...
-last page showing modulus of $row % 10

Many thanks for your invaluable help
 
<a href="page.php?page=1">page 1</a>
<a href="page.php?page=2">page 2</a>
<a href="page.php?page=3">page 3</a>
<a href="page.php?page=4">page 4</a>


$page = $_GET['page']-1;
$limit = '10';
$start = $page * 10;

$data=mysql_query("SELECT * FROM tablename limit $start,$limit")
 
Back
Top