Home > Backend Development > PHP Tutorial > PHP example code: AJAX pagination display data_PHP tutorial

PHP example code: AJAX pagination display data_PHP tutorial

WBOY
Release: 2016-07-21 14:56:09
Original
996 people have browsed it

Bangkejia (www.Bkjia.com) tutorial PHP example code: AJAX paging to display data.

Files for debugging

以下为引用的内容:


帮客之家提供教程LIEHUO.NET 关注站长,建设互联网!
<script> <br>function viewpage(p){ <br>if(window.XMLHttpRequest){ <br>var xmlReq = new XMLHttpRequest(); <br>} else if(window.ActiveXObject) { <br>var xmlReq = new ActiveXObject('Microsoft.XMLHTTP'); <br>} <br>var formData = "page="+p; <br>xmlReq.onreadystatechange = function(){ <br>if(xmlReq.readyState == 4){ <br>document.getElementById('content2').innerHTML = xmlReq.responseText; <br>} <br>} <br>xmlReq.open("post", "Example8_7_1.php", true); <br>xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); <br>xmlReq.send(formData); <br>return false; <br>} <br></script>



数据分页显示




Another file called Example8_7_1.php

The following is the quoted content:
header("Content-Type: text/html;charset=GB2312");
$pagesize=10;
//echo $_POST['page'];
$db=mysql_connect("localhost","root",""); //Create a database connection
mysql_query("set character set utf- 8");
mysql_select_db("optics");
$result = mysql_query("Select count(DISTINCT articleid) FROM product");
$myrow = mysql_fetch_array($result);
$ numrows=$myrow[0];
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
$pages++;
if (isset($_POST[ 'page'])){
$page=intval($_POST['page']);
}
else{
//Set to the first page
$page=1 ;
}
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
//Calculate Record offset
$offset=$pagesize*($page - 1);
//Read the specified number of records

//$result=mysql_query("select `id`, count ( * ) from ".book." GROUP BY `id` order by id desc limit $offset,$pagesize");
$result=mysql_query("select * from product GROUP BY `articleid` order by articleid desc limit $offset,$pagesize");
$num = @mysql_num_rows($result);

while ($row = @mysql_fetch_array($result,MYSQL_NUM)) {
$hotelname[] = $row[0];
$name[]=$row[1];
$author[]=$row[2];
$publisher[]=$row[3];
$isbn[]=$row[4];
$type[]=$row[5];
$smallpic[]=$row[6];
//$countpeople[] = $row[1];
}
echo "n";
echo "n";
echo "";
for($a=0;$ a<$num;$a++)
{
echo "n";
echo "";
echo "";
echo "";
echo "";
echo "";
echo " ";
echo " ";
echo "";
}
echo "
ID numberNameAuthorPublished CompanyISBN numberTypePrice
".$hotelname[ $a]."".$name[$a]."".$author[$a]."".$publisher[$a]."".$ isbn[$a]."".$type[$a]."
n";
echo "echo "border=0>";
echo "
";
echo "
";
echo "

Page ".$page."/ Total ".$pages." pages | Total ".$numrows." items | ";
if ($page>1) echo "Homepage | ";
if ($page>1) echo "Previous page | ";
if ($page<$pages) echo " Next page | ";
if ($page<$pages) echo "Last page< /a>";
echo "Go to page ";
echo "

";

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364312.htmlTechArticleLieHuo.Net tutorial PHP example code: AJAX paging display data. Files for debugging: The following is the quoted content: html head title Liehuo.net provides tutorials LIEHUO.NET Follow the webmaster,...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template