Ajax + php refreshing paging code (1/2)

Source: Internet
Author: User
Tags mysql tutorial

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.