PHP实例代码:AJAX 分页显示数据
帮客之家(www.Bkjia.com)教程 PHP实例代码:AJAX 分页显示数据。
调试用的文件
以下为引用的内容: <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> ![]() 数据分页显示 |
调用的另外一个文件 Example8_7_1.php
以下为引用的内容: header("Content-Type:text/html;charset=GB2312"); $pagesize=10; //echo $_POST['page']; $db=mysql_connect("localhost","root",""); //创建数据库连接 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{ //设置为第一页 $page=1; } $first=1; $prev=$page-1; $next=$page+1; $last=$pages; //计算记录偏移量 $offset=$pagesize*($page - 1); //读取指定记录数 //$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 "
echo " echo " |
||||||||||||||
"; echo " |
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide
