PHPCMS Get tags using

Source: Internet
Author: User
Tags mysql manual

Outline:

Get tags Overview
Get tag syntax
Get Tag Creation Tool
Get Call this system example
Get calls other system samples
First, Get tags overview
In layman's terms, get tags are phpcms defined to directly call the database inside the content of the simplification, friendly code, she can call the system and external data, only you have a certain understanding of SQL, she is your peerless good sword! It is suitable for people familiar with SQL statements. With her, we create a personalized website, it is very convenient to call out the content specified in the database. With conditional constraints, we can invoke different data under different conditions.
two, get label style
{Get dbsource= "" sql= "}
{/get}
third, get tag syntax
1.get tag attribute values must be enclosed in double quotation marks ("").
For example:
{Get sql= ""/}
The 2.get tag must contain an end tag, i.e. the correct get tag must be paired: The entire get tag has an end tag of "{/get}", or "/".
3.get tags contain variables, arrays and functions that must be included with "{}".
For example:
{str_cut ($r [title], 50)}
{$r [url]}
The limit of the number of bars in a 4.get label SQL statement. (rows= "")
Example: Display 10 information
{Get sql= "" Rows= "10"}
{/get}
The condition limit in the 5.get tag SQL statement. (where)
Example: Call information with column ID 1
{Get Sql= "select * from Phpcms_content where catid=1"}
Title: {$r [title]} url:{$r [URL]}
{/get}
Sort in a 6.get label SQL statement. (Order BY)
Example: Sort by Update date descending (DESC)
{Get Sql= "select * from Phpcms_content ORDER by updatetime Desc"}
{$r [title} url:{$r [URL]}
{/get}
The PHP function is nested inside the 7.get tag. (Refer to the 3rd above)
Example: Format output timestamp
{Date (' y-m-d ', $r [UpdateTime])}
8. The System data call (current database call)
{Get Sql= ""}
{/get}
Or
{Get sql= "" Return= "R"}
{/get}
9. The System data call 10
{Get sql= "" Rows= "10"}
{/get}
10. Different database calls to the same database account
{Get Dbname= "" sql= "}
{/get}
11. Different database account calls (different data source calls)
{Get dbsource= "" sql= "}
{/get}
12. Different database calls for different database accounts
{Get dbsource= "" Dbname= "" Sql= ""}
{/get}
13. The system data call, with paging
{Get sql= "" Page= "$page"}
{/get}
Paging: {$pages}
14. This system data call, custom return variable
{Get sql= "" return= "V"}
{$v []}
{/get}
Complete analysis of *get tag parameters
{Get dbsource= "data source" dbname= "Database" sql= "SQL statement" rows= "number of rows" return= "return variable name" page= "$page"}
Output code (with return variable values, arrays, functions, etc.)
{/get}
Dbname= "Database"-
(database name to be filled in when the database is added to the data source)
Note: This system call (the same database account, the same database name) can be omitted
sql= "SQL statement"--
SQL statements can refer to the MySQL manual, above get tag syntax 4th, 5, 6 points and SQL statement anatomy already mentioned points
Note: This parameter cannot be omitted
rows= "Number of rows"-
Number of rows, for example, displaying 10 messages: rows= "10"
Note: This parameter can be omitted
return= "Return variable name"--
Refer to get tag syntax 8th and 14th
Note: This parameter can be omitted
Page= "$page"-
with pagination
Note: This parameter can be omitted
Anatomy of a *sql statement
Sql= "select field from table name where conditional expression order by field DESC/ASC"
6 Complete Get tag code examples
1. Call the system single data, example (call ID 1 information, title length of not more than 25 kanji, display update date):
{Get Sql= "select * from Phpcms_content where contentid=1"/}
Title: {str_cut ($r [title])} url:{$r [URL]} Update Date: {date (' y-m-d ', $r [UpdateTime])}
2. Call the system more than one data, example (call column ID 1 through the audit of 10 information, the title length of not more than 25 Chinese characters, display the update date):
{Get Sql= "select * from Phpcms_content where catid=1 and status=99 order by updatetime Desc" rows= "10"}
Title: {str_cut ($r [title])} url:{$r [URL]} Update Date: {date (' y-m-d ', $r [UpdateTime])}
{/get}
3. With pagination, example (call column ID 1 through the audit of 10 information, the title length of not more than 25 characters, display the update date, with pagination):
{Get Sql= "select * from Phpcms_content where catid=1 and status=99 order by updatetime Desc" rows= "" Page= "$page"}
Title: {str_cut ($r [title])} url:{$r [URL]} Update Date: {date (' y-m-d ', $r [UpdateTime])}
{/get}
Paging: {$pages}
4. Custom return variables, example (call column ID 1 through the audit of 10 information, the title length of not more than 25 characters, display the update date, the return variable is $v):
{Get Sql= "select * from Phpcms_content where catid=1 and status=99 order by updatetime Desc" rows= "" return= "V"}
Title: {str_cut ($v [title])} url:{$v [URL]} Update Date: {date (' y-m-d ', $v [UpdateTime])}
{/get}
5. Call other databases under the same account, example (call database for BBS, category ID 1 of 10 newest topics, subject length not more than 25 kanji, show update date):
{Get Dbname= "BBS" sql= "select * from Cdb_threads where fid=1 order by dateline Desc" rows= "10"}
Subject: {Str_cut ($r [subject],)} url:http://bbs.phpcms.cn/viewthread.php?tid={$r [tid]} Update Date: {date (' y-m-d ', $r [ Dateline])}
{/get}
6. Call external Data, example (call data source for BBS, category ID 1 of 10 newest topics, subject length not more than 25 kanji, display update date):
{Get dbsource= "BBS" sql= "select * from Cdb_threads where fid=1 order by dateline Desc" rows= "10"}
Subject: {Str_cut ($r [subject],)} url:http://bbs.phpcms.cn/viewthread.php?tid={$r [tid]} Update Date: {date (' y-m-d ', $r [ Dateline])}
{/get}
Iv. get tag Creation tool
1. Get the Get Tag code

For example, just now our data source selects "This system", the data table selects "The content model", the field name we display "The ID, the title, the summary, the link address, the publication time", the condition chooses id=1, the sort sorts by the ID descending order, the check "is paginated", each page shows the number to be set to "10

We can get the system auto-generated get tag code, as follows:

{Get sql= "select ' ContentID ', ' title ', ' description ', ' url ', ' inputtime ' from ' phpcms_content ' WHERE ' contentid ' = ' 1 ' ORDER by ' ContentID ' DESC "rows=" "Page=" $page "}
{$r [ContentID]}
{$r [title]}
{$r [description]}
{$r [url]}
{$r [Inputtime]}
{/get}
{$pages}
The analysis is as follows:
{Get sql= "select ' ContentID ', ' title ', ' description ', ' url ', ' inputtime ' from ' phpcms_content '" WHERE ' contentid ' = ' 1 ' ORDER by ' ContentID ' DESC rows= "ten" page= "$page"}
Condition is id=1, sort sorted by ID descending, display 10 rows, with pagination

{$r [ContentID]}
Id

{$r [title]}
Title

{$r [description]}
Summary

{$r [url]}
Link Address

{$r [Inputtime]}
Release time
{/get}
{$pages}
Page out
2. Inserting the code into the template file
The get tag code is as follows:
{Get dbsource= "discuz" sql= "Select ' Author ', ' Subject ', ' lastpost ' from ' cdb_threads ' ORDER by ' lastpost ' DESC" rows= "3"}
{$r [author]}
{$r [subject]}
{$r [Lastpost]}
{/get}


More website Announcements
Add (a slightly beautified get tag code):

Forum Latest Posts

{Get dbsource= "discuz" sql= "Select ' Author ', ' Subject ', ' lastpost ' from ' cdb_threads ' ORDER by ' lastpost ' DESC" rows= "3"}
({$r [author]}) {Str_cut ($r [subject], A, "")} date:{date ("y-m-d", $r [Lastpost])}

{/get}

PHPCMS Get tags using

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.