Publish one of the strongest PHP Universal paging classes _php Tutorials

Source: Internet
Author: User
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/}


















{Dede:datalist} {/dede}
Aa Bb Cc Tt
[field:aa/] [field:bb/] [field:cc/] [Field:tt function=date ("y-m-d h-i-s", "@me")/]

{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 ...

  • 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.