Ajax + php no-refreshing paging code. Here we use php + js + ajax to implement no-refreshing paging code for data.
Ajax + php tutorial without refreshing paging code
Here we use php + webpage special effects + ajax to implement the Code of refreshing pagination for data.
*/
// Index. php file
Header ("content-type: text/html; charset = UTF-8 ");
Error_reporting (e_all ^ e_notice );
Include ('pagination _ class. php ');
Mysql tutorial _ connect ('localhost', 'root', '') or die (mysql_error ());
Mysql_select_db ('mydemo ');
Mysql_query ("set names 'utf8 '");
?>
<Script language = "webpage effect" src = "pagination. webpage effect"> </script>
<Link rel = "stylesheet" type = "text/css tutorial" 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 File
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