PHPCMS get tag overview, get tag syntax, get tag creation tool, get call this system example, get call other system examples
First, Get tags overview
in layman 's terms, the get tag is a simple, friendly code that PHPCMS defines to directly invoke the contents of the database, and she can invoke 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}
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
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
{Get sql= "" Page= "$page"}
{/get}
Paging: {$pages}
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 ]} Updated: {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 ]} Updated: {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}