Use eval and loop to read the contents of the database directly in the template and output

Source: Internet
Author: User
Tags eval

As the saying goes, it's good to own hands!

Today realizes this, takes out to share with the novice, the great god please detour!

Full post code:

<!--{eval $slides = Db::fetch_all ("select * from ' pre_common_block_item ' WHERE ' bid ' =15 ORDER by ' displayorder ' ASC, ' ID ' DESC LIMIT 0, 10 ');} -

<!--{Loop $slides $slide}-->

<a href= "$slide [url]" target= "_black" ></a>

<!--{/loop}-->

Copy Code

Code parsing:


<!--{eval $slides = Db::fetch_all ("//Execute SQL statement

SELECT *//Read all fields

From ' Pre_common_block_item '//Data sheet can be customized this is a DIY post content table

WHERE ' bid ' = 15//Query criteria bid is a DIY module ID

ORDER BY ' Displayorder ' ASC, ' id ' DESC//Sort condition

LIMIT 0, 10//Get the top 10 message

");} -

<!--{Loop $slides $slide}-->//Loops $slides array use $slide [field name] to get content

<a href= "$slide [url]" target= "_black" ></a>

<!--{/loop}-->


Hope to be able to help new people! Explanation is not in place also please understanding, welcome criticism correct, do not like to spray!


Use eval and loop to read the contents of the database directly in the template and output

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.