PHP Paging Query

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Untitled Document </title>

<body>
<form action= "fenye.php" method= "Get" >
<table border= "1" bordercolor= "#FF0000" >
<?php
Class page
{
Private $pagesize;
Public $absolutepage;
Private $pagecount;
Private $totaINum;
Private $prevpage;
Private $nextpage;

Function page ($pagesize, $absolutepage)
{
$this->pagesize= $pagesize;
$this->absolutepage= $absolutepage;
}

Public Function Listinfo ()
{
$con =mysql_connect ("localhost", "root", "120911");
if (! $con)
{
Die (' Connection failed: '. mysql_error);
}
if (!mysql_select_db ("MyDB", $con))
{
Die (' Select database failed: '. mysql_error);
}
$result =mysql_query ("Select*from Persons");
Mysql_close ($con);
Total number of bars in the queried table
$this->totainum=mysql_num_rows ($result);
Calculate Total Pages
$this->pagecount= (int) (($this->totainum-1)/($this->pagesize)) +1;
Is_numeric detects if the variable is a number. Absoulutepage as the current page


if ($this->absolutepage== "" | |! Is_numeric ($this->absolutepage))
{
$this->absolutepage=1;
}
if ($this->absolutepage> $this->pagecount)
{
$this->absolutepage= $this->pagecount;
}
if ($this->totainum>1&& $this->absolutepage>1)
{
$this->prevpage= $this->absolutepage-1;
}
if ($this->absolutepage>=1&& $this->absolutepage< $this->pagecount)
{
$this->nextpage= $this->absolutepage+1;
}


?>
&LT;TR align= "center" >
<td>ID</td>
<td> Surname </td>
<td> name </td>
<td> Age </td>
</tr>
<?php
if (Mysql_data_seek ($result, ($this->absolutepage-1) * $this->pagesize))
{
for ($i =0; $i < $this->pagesize; $i + +)
{
if ($info =mysql_fetch_array ($result))
{
?>
&LT;TR align= "center" >
<td><?php echo $info ["PersonID"];? ></td>
<td><?php echo $info ["FirstName"];? ></td>
<td><?php echo $info ["LastName"];? ></td>
<td><?php echo $info ["age"];? ></td>
</tr>
<?php

}
}
}
}
Public Function ToPage ()
{
?>
<tr>
&LT;TD colspan= "5" >

Altogether <?php Echo $this->totainum?> students, <?php echo $this->absolutepage?> page/Total
<?php echo $this->pagecount?> page:

<?php
echo "<a href= '? absolutepage=1 ' > Home </a>";
echo "<a href= '? absolutepage= $this->prevpage ' > Prev </a>";
echo "<a href= '? absolutepage= $this->nextpage ' > Next </a>";
echo "<a href= '? absolutepage= $this->pagecount ' > End </a>";
?>

</td>
</tr>
<?php
}
}
$obj =new page (3,$_get[absolutepage]);
$obj =new page (3,$_get[' AbsolutePage ');
$obj->listinfo ();
$obj->topage ();
?>
</table>
</form>
Undefined Index: Parameter not passed over <br>
Use of undefined constant: non-standard writing
</body>

PHP Paging Query

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.