If you have studied ASP, you must know that it has a very powerful paging feature called DataList, and this class simulates a part of this function, I dare to use "strong" to define it, because as a generic page class, this class really does "universal".
Talk less, tell me about how to use it now.
1. First create a new table for testing
CREATE TABLE ' Test ' (
' AA ' INT not NULL auto_increment PRIMARY KEY,
' BB ' VARCHAR (not NULL),
' CC ' VARCHAR (not NULL),
' TT ' INT DEFAULT 0 not NULL
);
2, make a template file, save 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. Write code that calls this class
Database connection information is in config_base.php this file is set
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 ();
?>
Look at the effect, do a sub-file is so simple, but also completely achieve the separation of the page and logic
What should I do if I want to add a get string 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 ();
?>
Is there anything else that can't be solved?
If there is a Boolean value of the field, I want to output different content when the output, in fact, it is not difficult to implement
Dede template engine supports the use of custom 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 ();
?>
What you don't need to do in a program is to change the template
[Field:aa function= "Getmyname (@me)"/]
The value returned is the value returned by the function.
This is almost perfect, the only thing is that the link to the paging list is fixed, but you can improve it.
http://www.bkjia.com/PHPjc/508494.html www.bkjia.com true http://www.bkjia.com/PHPjc/508494.html techarticle If you have studied ASP, you must know that it has a very powerful paging function called DataList, and this class here simulates a part of this function, I dare to use the power to ...