程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> ajax +php無刷新分頁代碼(1/2)

ajax +php無刷新分頁代碼(1/2)

編輯:關於PHP編程

ajax +php無刷新分頁代碼 我們這裡是利用php+js+ajax實現數據無刷新分頁代碼哦。

ajax +php教程無刷新分頁代碼
我們這裡是利用php+網頁特效+ajax實現數據無刷新分頁代碼哦。
*/

//index.php文件
header("content-type: text/html; charset=utf-8");
error_reporting(e_all^e_notice);
include('pagination_class.php');
mysql教程_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db('mydemo');
mysql_query("set names 'utf8'");
?>
<script language="網頁特效" src="pagination.網頁特效"></script>
<link rel="stylesheet" type="text/css教程" href="style.css" />
<?
$qry = "select * from students";
$searchtext = "";
if($_request['search_text']!=""){
 $searchtext = $_request['search_text'];
 $qry .=" where name like '$searchtext%'";
}
//for pagination
$starting=0;
$recpage = 2;//number of records per page
 
$obj = new pagination_class($qry,$starting,$recpage);  
$result = $obj->result;

   
   ?><form name="form1" action="testpage.php" method="post">
   
   <table border="1" align="center" width="40%">
   <tr>
     <td colspan="2">
    search <input type="text" name="search_text" id="search_text" value="<?php echo $searchtext; ?>">
     <input type="submit" value="search">
     </td>
   </tr>
   <tr><td colspan="2">
   
   <div id="page_contents">
    <table border="1" align="center" width="100%">
    <tr><td>sl no</td><td>name</td></tr>
    <?if(mysql_num_rows($result)!=0){
     $counter = $starting + 1;
     while($data = mysql_fetch_array($result)) {?>
      <tr>
      <td><? echo $counter; ?></td>
      <td><? echo $data['name']; ?></td>
      </tr><?
      $counter ++;
     } ?>
    
      
     <tr><td colspan="2"><? echo $obj->anchors; ?></td></tr>
     <tr><td colspan="2"><? echo $obj->total; ?></td></tr>
    <?}else{?>
     <tr><td align="center" colspan="2">no data found</td></tr>
    <?}?>
    </td></tr>
    </table>
   </div>
   </td></tr>
  </table></form>
   


 pagination.js文件
   

      function $()
{
  var elements = new array();
  for (var i = 0; i < arguments.length; i++)
  {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getelementbyid(element);
    if (arguments.length == 1)
      return element;
    elements.push(element);
  }
  return elements;
}

var xmlhttp
function pagination(page)
{
xmlhttp=getxmlhttpobject();
if (xmlhttp==null)
  {
  alert ("your browser does not support ajax!");
  return;
  }
var url="test_sub.php";
url = url+"?starting="+page;
url = url+"&search_text="+$('search_text').value;
url=url+"&sid="+math.random();
xmlhttp.onreadystatechange=statechanged;
xmlhttp.open("get",url,true);
xmlhttp.send(null);
}

function statechanged()
{
if (xmlhttp.readystate==4)
{
$("page_contents").innerhtml=xmlhttp.responsetext;
}
}

function getxmlhttpobject()
{
var xmlhttp=null;
try
  {
  // firefox, opera 8.0+, safari
  xmlhttp=new xmlhttprequest();
  }
catch (e)
  {
  // internet explorer
  try
    {
    xmlhttp=new activexobject("msxml2.xmlhttp");
    }
  catch (e)
    {
    xmlhttp=new activexobject("microsoft.xmlhttp");
    }
  }
return xmlhttp;
}

1 2

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved