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 /}
Aa |
Bb |
Cc |
Tt |
{Dede: datalist}
[Field: aa/] |
[Field: bb/] |
[Field: cc/] |
[Field: tt function = 'date ('Y-m-d H-I-s', '@ me')'/] |
{/Dede}
{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 ();