Pear::P integrated application of Ager and Ajax

Source: Internet
Author: User
Tags pear

As a PHP developer, perhaps the most useful thing is Pear's class library. We know, Pear::P ager is specifically for paging, while Pear::html_ajax is a class library of AJAX applications. But Pager is more than just a page link for HTML, which is already ready for Ajax that is redder than super girls, and see how these two packages are integrated.

Pager and Javascript

Now that the first step, pager has been able to build a link to JavaScript, and Ajax integration, theoretically should be able to implement, the following is a pager and JavaScript pagination example:

Require_once ' pager/pager.php ';
$data = range (1, 100); An array of data to Paginate
$pager _params = Array (
' Mode ' => ' sliding ',
' Append ' => false,//don ' t append the get parameters to the URL
' Path ' => ',
' FileName ' => ' Javascript:revealdiv (%d) ',//pager replaces '%d ' with the page number ...
' Perpage ' =>,//show items per page
' Delta ' => 5,
' ItemData ' => $data,
);
$pager = & Pager::factory ($pager _params);
$n _pages = $pager->numpages ();
$links = $pager->getlinks ();
?>
<script type= "Text/javascript" language= "JavaScript" >
var n_pages = <?php echo $n _pages?>;
function Revealdiv (n)
{
for (var count = 1; count <= n_pages; count++) {
document.getElementById ("page" +count). Style.display = ' None ';
}
document.getElementById ("page" +n). Style.display = ' block ';
}
</script>
<style type= "Text/css" >
Div.page {
Background: #FFFF99;
border-top:1px solid #FFBF99;
border-bottom:1px solid #FFBF99;
}
</style>
<body>
<?php echo $links [' pages '];?>
<?php
For ($i =1 $i <= $n _pages + + $i) {
Echo ' <div class= ' page ' id= ' page '. $i. ' > ';
Echo ' foreach ($pager->getpagedata ($i) as $item) {
Echo ' Item '. $item. ' <br/> ';
}
Echo ' </div> ';
}
?>
<script type= "Text/javascript" language= "JavaScript" >
Revealdiv (1);
</script>
</body>

In the example, put all the data of pagination into a DIV tag, define two more important parameters is path (empty) and Filename,filename originally should be linked file name, but here with JavaScript replaced.

Related Article

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.