Bangkejia (www.Bkjia.com) tutorial PHP example code: AJAX paging to display data.
Files for debugging
以下为引用的内容: <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 "
echo " echo " | ||||||||||||||
"; echo " "; echo " Page ".$page."/ Total ".$pages." pages | Total ".$numrows." items | "; |