Publish one of the strongest PHP General page classes

Source: Internet
Author: User
Tags require
Paging

If you've ever 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 ' >
&LT;TD width= ' 10% ' >aa</td>
&LT;TD width= ' 30% ' >bb</td>
&LT;TD width= ' 30% ' >cc</td>
&LT;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 ' >
&LT;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 ();
$dlist->close ();
?>
Look at the effect, do a sub file is so simple, but also fully implemented the page and logic separation
What should I do if I want to add a get string to pass to the query?
Easy
If the additional 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 one of the fields is Boolean, I want to output different content according to different conditions, actually not difficult to achieve
The Dede template engine supports the use of custom functions
?
Require ("inc_datalist.php");
if (!isset ($keyword)) $keyword = "";
function Getmyname ($mname)
{
if ($mname = = "Dede") return to "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 link to the page list is fixed, but you can improve it.



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.