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 /}
| 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 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.