PHPcmsv9 The get label SQL statement limit is invalid and the num and rows attributes are invalid. Solution

Source: Internet
Author: User
Tags php template

The PHPcms v9 get label SQL statement limit is invalid and the num and rows attributes are invalid. So far, it is an old problem. There are some superficial solutions on the network, however, on a daily basis, no solution or explanation is found to solve the problem from the bottom layer, layer template tag parsing, and template engine code. Today, we also encountered this problem when using the get tag SQL statement to call data. After research, we found the cause of the problem and sorted out this article to help php enthusiasts.
Error Description: I want to retrieve the latest 6 data records from the data table!

The code is as follows: Copy code
<Dl class = "about_text1">
<Dt> Class = "tupian"/>{$ m_more ['Nick ']} latest article
</Dt>
{Pc: get SQL = "SELECT * FROM 'cms _ talkcar 'a left join 'cms _ member' B
ON a. username = B. username left join 'cms _ member_detail 'c ON B. userid = c. userid
WHERE a. catid = $ catid AND status = 99 and a. username = '$ username' ORDER
Inputtime DESC "num = '8 '}
{Loop $ data $ r}
<Dd> <I> </I> <a href = "{$ r [url]}" title = "" target = "_ blank"> {$ r [title]} </a> </dd>
{/Loop}
{/Pc}
</Dl>

The result shows that more than 6 data entries are displayed, and all 10 data entries in the database are displayed. This indicates that the rows attribute is invalid.
Later, the SQL statement was changed: SELECT * FROM 'cms _ talkcar 'a LEFT join' cms _ member 'B ON. username = B. username left join 'cms _ member_detail 'c ON B. userid = c. userid WHERE. catid = $ catid AND status = 99 and. username = '$ username' order by inputtime DESC limit "result: the system reports the following SQL syntax error:

Obviously, this is the limit of "limit 20" added by default when the phpcms system does not obtain a valid parameter for the specified number of data entries when parsing tags. Now it seems that simply adding limit 8 to the source SQL statement is not acceptable.
Daily users quickly know that the specified quantity uses the num attribute, but as the internet knows, the num attribute is also invalid (why is the num attribute correct? The specified number of parameters will be answered in the underlying code explanation ). The returned value is still the limit of "limit 20" appended by default.
In this case, an error occurred while parsing the source code to obtain the num attribute value and determine whether the default value is 20.

The following describes the solution on the network, and explains how to remove errors in the source code to use the num attribute to specify the number of data entries to be retrieved.
Solutions on the network (source: phpcms official Forum ):
1. Method 1: Add the start attribute, such

The code is as follows: Copy code
{Pc: get SQL = "SELECT title, url FROM v9_news where catid = 9 and status = 99 order by updatetime desc "start =" 0 "num =" 4 "return =" v "}

You can add start and num for control. In this way, the data from 0 to 4 is obtained.
2. Method 2 (compared to the absolute method), add -- comment out the limit 20 automatically added by the system:

The code is as follows: Copy code
{Pc: get SQL = "SELECT title, url FROM v9_news where catid = 9 and status = 99 order by updatetime desc limit 0, 4 --" return = "v "}

Note that the two minus signs behind 4 have commented out the LIMIT statement that comes with v9! This will not conflict with the limit you added.

The method for removing source code errors at the underlying layer provided by daily users (just change the code line !) :

Find the pc_tag () method in the/phpcms/libs/classes/template_cache.class.php template resolution cache file, which is about 115 rows, and then in

The code is as follows: Copy code

131 $ str = '';
132 $ num = isset ($ num) & intval ($ num )? Intval ($ num): 20;

Insert a sentence between row 131st and row 132nd, as shown below:

131 $ str = '';
132 $ num = eval ("return". $ num. ";"); // Insert statement
133 $ num = isset ($ num) & intval ($ num )? Intval ($ num): 20;

This is a success! Update the cache in the background, and test it. You can use the num attribute in the get tag to specify the data quantity.

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.