ajax +php无刷新分页代码
来源:未知
时间:2014-11-27 22:51 作者:xxadmin
阅读:次
[导读] 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( s...
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="javascript" src="pagination.js"></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%'";
-
}
-
-
$starting=0;
-
$recpage = 2;
-
-
$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)
-
|