<! 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;
}
?>
<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))
{
?>
<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>
<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