Home > Backend Development > PHP Tutorial > phpcms v9 tag call, function, sql_PHP tutorial

phpcms v9 tag call, function, sql_PHP tutorial

WBOY
Release: 2016-07-20 11:16:09
Original
961 people have browsed it

1. Intercept the call title length

{str_cut($r[title],36,'')}

2. Formatting time

Call formatting time 2011-05-06 11:22:33

{date('Y-m-d H:i:s',$r[inputtime])}

3. Calling multiple columns & calling multiple recommendations

Calling requirements: The article range is 59, 60 and 61, and pushed to two recommendation positions: 27 and 28;
Starting from the third article, 7 articles are called continuously.

{pc:get sql="SELECT * FROM v9_news WHERE id IN (SELECT id FROM v9_position_data WHERE posid in(27,28) and catid in(59,60,61)) order by listorder DESC" cache="3600 " start="3" num="7" return="data" }
{loop $data $n $r}

  • ·

    1. Call a single piece of data from this system, example (call the information with ID 1, the title length does not exceed 25 Chinese characters, and display the update date):
    {get sql="select * from phpcms_content where contentid=1" /}
    Title: {str_cut($r[title], 50)} URL: {$r[url]} Update date: {date('Y-m-d', $r[updatetime])}
    2. Call multiple pieces of data from this system, example (call 10 pieces of information that have passed the review with the column ID 1, the title length does not exceed 25 Chinese characters, and the update date is displayed):
    {get sql="select * from phpcms_content where catid =1 and status=99 order by updatetime desc" rows="10"}
    Title: {str_cut($r[title], 50)} URL: {$r[url]} Update date: {date(' Y-m-d', $r[updatetime])}
    {/get}
    3. With paging, example (call 10 pieces of information with column ID 1 that passed the review, the title length does not exceed 25 Chinese characters, display Update date, with paging):
    {get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10" page="$page"}
    Title: { str_cut($r[title], 50)} URL: {$r[url]} Update date: {date('Y-m-d', $r[updatetime])}
    {/get}
    Paging :{$pages}
    4. Customize return variables, example (call 10 pieces of information that have passed the review with column ID 1, the title length does not exceed 25 Chinese characters, the update date is displayed, and the return variable is $v):
    {get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10" return="v"}
    Title: {str_cut($v[title], 50) } URL: {$v[url]} Update date: {date('Y-m-d', $v[updatetime])}
    {/get}
    5. Call other databases under the same account, example (Call the 10 latest topics whose database is bbs, category ID is 1, the topic length does not exceed 25 Chinese characters, and the update date is displayed):
    {get dbname="bbs" sql="select * from cdb_threads where fid=1 order by dateline desc" rows="10"}
    Subject: {str_cut($r[subject], 50)} URL: http://bbs.phpcms.cn/viewthread.php?tid={$r[ tid]} Update date: {date('Y-m-d', $r[dateline])}
    {/get}
    6. Calling external data, example (the calling data source is bbs, the classification ID is 1 The 10 latest topics, the topic length does not exceed 25 Chinese characters, and the update date is displayed):
    {get dbsource="bbs" sql="select * from cdb_threads where fid=1 order by dateline desc" rows="10" }
    Subject: {str_cut($r[subject], 50)} URL: http://bbs.phpcms.cn/viewthread.php?tid={$r[tid]} Update date: {date(' Y-m-d', $r[dateline])}
    {/get}

    I wonder if any friends have encountered when these methods cannot meet their needs?

    For example: Take out the 3rd to 10th records with the most comments. Some people say that I am unnecessary. Generally, there is no reason not to take the first and second records with the most comments, because the thumbnails of PHPCMS are like 4:3. The size is better, but the thumbnail effect is not good for long strips (such as 3:4). In order to manually update the first and second records with the most comments, I don't want to automatically update and read the first two records.

    The key point is order by B.comments desc LIMIT 3,7 (meaning starting from the 3rd record, reading 7 pieces of data downwards) This is often used in MYSQL, I had the idea of ​​​​trying it, and the result It is possible.

    The effect is as follows:

    I hope friends who are doing PHPCMS development can learn and share together

    phpcms V9 retains the usage method of get tag in 2008

    It includes 2 methods, one is internal data and the other is external data

    Let’s first analyze how to use internal data

    1. Calling internal data

    {pc:get sql="SELECT * FROM `XX` WHERE fid =$ltid AND digest =2 AND ifupload =1 ORDER BY tid DESC" num="2" cache="3600" return="data" }
    {loop $data $r}

    . . . . .

    {/loop}{/pc}

    It can be seen that the get statement supports the usage of num but does not support limit 5, 5. Such usage

    It’s really a pity

    num is the number of calls

    2. Calling external data

    { pc : get sql = "SELECT * FROM phpcms_member" cache = "3600" page = "$page" dbsource = "discuz" return = "data" }

      { loop $data $key $val }

      { $val [ username ]}< br />

      { /loop}

      { $pages }

      {/ pc }

      One is the data source, and the other is the generated pages turning effect

      This article is reprinted from http://www.itokit.com/2012/0119/73007.html

      www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440132.htmlTechArticle1. Intercept the call title length {str_cut($r[title],36,'')} 2. Format The formatting time calls the formatting time 2011-05-06 11:22:33 {date('Y-m-d H:i:s',$r[inputtime])} 3. Multiple columns call multiple recommended positions...
  • source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template