If you have studied ASP.net, you must have known it had a DataList in it. The paging function is very powerful, this class simulates a part of this function, I dare to use "strong" to define it, because as a General page class, this class is really "universal".
Talk less, and immediately introduce how it is used.
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, the production of a template file, save as: test.htm
{Dede:page pagesize=15/}
<table width= ' 100% ' border= ' 0 ' cellpadding= ' 1 ' cellspacing= ' 1 ' bgcolor= ' #CCCCCC ' >
<tr bgcolor= ' #F8FFEE ' align= ' center ' >
<TD width= ' 10% ' >aa</td>
<TD width= ' 30% ' >bb</td>
<TD width= ' 30% ' >cc</td>
<TD width= ' 30% ' >tt</td>
</tr>
{Dede:datalist}
<tr bgcolor= ' #FFFFFF ' align= ' center ' >
<td>[field:aa/]</td>
<td>[field:bb/]</td>
<td>[field:cc/]</td>
<td>[field:tt function= ' Date ("y-m-d h-i-s", "@me") '/]</td>
</tr>
{/dede}
<tr bgcolor= ' #F8FFEE ' >
<TD colspan= ' 4 ' >
{Dede:pagelist listsize=3/}
</td>
</tr>
</table>
3, write the code that calls this class
Database connection information is 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 ();