Example of calling multi-condition data using the Phpcms V9 get statement

Source: Internet
Author: User


In phpcms, The get statement is a flexible condition statement. When phpcms comes with data that cannot be called by tags, we can use the get statement for direct SQL calls, this is common in calling multi-level data, especially custom condition data.
Let's take a look at a common pc tag call data code of phpcms:


{Pc: content action = "lists" catid = "$ catid" num = "25" order = "id DESC" page = "$ page "}
<Ul class = "list lh24 f14">
{Loop $ data $ r}
<Li> <span class = "rt"> {date ('Y-m-d H: I: S', $ r [inputtime])} </span> · <a href = "{$ r [url]}" target = "_ blank" {title_style ($ r [style])}> {$ r [title]} </a> </li>
{If $ n % 5 = 0} <li class = "bk20 hr"> </li> {/if}
{/Loop}
</Ul>
<Div id = "pages" class = "text-c" >{$ pages} </div>
{/Pc}

This is an ordinary way of calling data. If we call a product in a model and the where condition exists, the code is as follows:


{Pc: content action = "lists" catid = "6" moreinfo = "1" where = "function = 1" num = "8" order = "id DESC "}
{Loop $ data $ r}
<Li> · <a href = "{$ r [url]}" title = "{$ r [title]}" class = "xiariboke"> {str_cut ($ r [title], 64) }</a> </li>
{/Loop}
{/Pc}

Note that the where = "function = 1 & Prime; condition indicates that all the parameters in content are considered as filter conditions of another SQL statement, we can directly call the above code into get. The code is as follows:


{Pc: get et SQL = "select * from xiariboke_pictures where catid = 6 and function = 1 order by id desc" rows = "8" return = "data "}
{Loop $ data $ r}
<Li> · <a href = "{$ r [url]}" title = "{$ r [title]}"> {str_cut ($ r [title], 64) }</a> </li>
{/Loop}
{/Pc}

Is this more convenient? Of course, if you call a summer blog in a simple way like this, we suggest making pc labels. But if you encounter more complicated conditional statements, obviously, it is more convenient to use the get statement. Well, let's look at your personal needs. If you want to steal some lazy kids shoes, just get the statement, the only advantage of get is that it is highly scalable and can be combined with a variety of SQL condition statements. In this case, pc is a little weak.


If the front-end template calls the product list by purpose and uses the product list as a Tab, how can this data be defined if one Tab shows a purpose?

First, we add a field "function" in the model as the purpose. The drop-down menu is used to pre-define several optional purposes, assume that the field IDs of these options are 1, 2, 3, and 4.

You can use the following code to call a product whose "function" field ID is 1:

{Pc: content action = "lists" catid = "6" moreinfo = "1" where = "function = 1" num = "8" order = "id DESC "}
{Loop $ data $ r}
<Li> · <a href = "{$ r [url]}" title = "{$ r [title]}" class = "cmsyou"> {str_cut ($ r [title], 64) }</a> </li>
{/Loop}
{/Pc}

In this way, you can find eight products whose topic ID is 6 (image model) and whose use ID is 1.

In the same way, you can use the GET statement to make this call:

{Pc: get et SQL = "select * from cmsyou_pictures where catid = 6 and function = 1 order by id desc" rows = "8" return = "data "}
{Loop $ data $ r}
<Li> · <a href = "{$ r [url]}" title = "{$ r [title]}"> {str_cut ($ r [title], 64) }</a> </li>
{/Loop}
{/Pc}

Note that the above code uses the GET statement to specify the cmsyou_pictures header of the database. Therefore, you must customize the modification according to the table header and the table shard of the model.

In contrast, we can see that the GET call method is similar to the MYSQL call statement, so we can perform multiple conditional filtering based on this method. The first sentence above is:
{Pc: get et SQL = "select * from cmsyou_pictures where catid = 6 and function = 1 order by id desc" rows = "8" return = "data "}
The Where clause is used for filtering. When the catid = 6 and function = 1 conditions are met, the clause is called. If more criteria are needed, you can try multiple and or.

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.