Announcing the strongest 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. this class here imitates this function, I dare to use "strong" to define it, because as a general page class, this

If you have learned Asp.net, you must know that there is a built-in paging function such as datalist which is very powerful. this class here imitates this function, I dare to use "strong" to define it, because as a general page class, this class truly achieves "general ".
Let's talk about how to apply 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 keep 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 consequences, it is so simple to make a sub-file, and the complete implementation of the page and logic respectively
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 application 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 ();

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.