Publish the most powerful PHP Generic paging class

Source: Internet
Author: User
If you have learned Asp.net, you must know that there is a built-in paging function, such as datalist, which is very powerful. here this class simulates this function. I dare to use & ldquo; powerful & rdquo; is defined as a general page class, which truly achieves & ldquo; General & rdquo ;. Less nonsense SyntaxHigh if you have learned Asp.net, you must know that there is a built-in paging function such as datalist which is very powerful. here this class simulates this function, I dare to use "powerful" to define it, because as a general page class, this class is truly "universal ".
Let's talk about how to use it.
1. create a new table for testing.
Create table 'test '(
'A' int not null AUTO_INCREMENT primary key,
'BB' VARCHAR (50) not null,
'CC' VARCHAR (50) not null,
'TT' int default 0 NOT NULL
);
2. create a template file and save it as test.htm.
{Dede: page pagesize = 15 /}


















{Dede: datalist} {/Dede}
Aa Bb Cc Tt
[Field: aa/] [Field: bb/] [Field: cc/] [Field: tt function = date ("Y-m-d H-I-s", "@ me")/]

{Dede: pagelist listsize = 3 /}

3. compile the code that calls this class.
The connection information of the database is set in the file config_base.php.
Showtable. php
Require ("inc_datalist.php ");
$ Dlist = new DataList ();
$ Dlist-> Init ();
$ Dlist-> SetTemplet ("./test.htm ");
$ Dlist-> SetSource ("select * from ttt ");
$ Liststring = $ dlist-> Display ();
$ Dlist-> Close ();
?>
Looking at the results, it is so simple to make a file sharding, and completely achieves the separation of pages and logic.
What should I do if I want to add a GET string to be passed to the query?
Easy
If the added query string is keyword
Require ("inc_datalist.php ");
If (! Isset ($ keyword) $ keyword = "";
$ Dlist = new DataList ();
$ Dlist-> Init ();
$ Dlist-> SetParameter ("keyword", $ keyword );
$ Dlist-> SetTemplet ("./test.htm ");
$ Dlist-> SetSource ("select * from ttt where bb like % $ keyword % ");
$ Liststring = $ dlist-> Display ();
$ Dlist-> Close ();
?>
What else can't be solved?
If a field is a Boolean value, it is not difficult to output different content according to different situations.
The Dede template engine supports user-defined functions.
Require ("inc_datalist.php ");
If (! Isset ($ keyword) $ keyword = "";
Function GetMyName ($ mname)
{
If ($ mname = "dede") return "My Name ";
Else return $ mname;
}
$ Dlist = new DataList ();
$ Dlist-> Init ();
$ Dlist-> SetParameter ("keyword", $ keyword );
$ Dlist-> SetTemplet ("./test.htm ");
$ Dlist-> SetSource ("select * from ttt where bb like % $ keyword % ");
$ Liststring = $ dlist-> Display ();
$ Dlist-> Close ();
?>
You don't need to do anything in the program. you need to change the template.
[Field: aa function = "GetMyName (@ me)"/]
The returned value is the value returned by the function.

In this way, the only difference is that the link to the paging list is fixed, but you can improve it.

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.