Examples of dedecms running PHP code and MySQL statements

Source: Internet
Author: User
Tags php file php and php code

One, Dede run PHP code

Example 1:

{dede:name runphp= ' yes '}
$str = "Hello";
@me = $str;
@me. = "World";
{/dede:name}

Result: Hello World

Description: "Name" is any defined name, @me represents the current value, which is the value to output the last @me.

For example 2


{Dede:field runphp= ' yes '}
$STR = "World";
$DedeMeValue = "Hello";
$DedeMeValue. = $str;
{/dede:field}

Result: Hello World

Note: If you directly introduce PHP and want to get the running value, you must use the $DedeMeValue to indicate the value of the final return after running this PHP (and therefore cannot be mixed with HTML)

For example 3

{dede:list perpage= ' 10 '}
[Field:id runphp= "yes"]
$dsql = new Dedesql (false);
$a = "Select A.address from Dede_addonarticle as a where a.aid= @me";
$arcRow = $dsql->getone ($a);
@me = '. $arcRow [address].
[/field:id]
{/dede:list}

Second, the reference PHP file

If you want to use PHP in the Include file, add source= ' value '

{dede:include runphp= ' yes ' source= ' value ' file= '/}

Third, Dede running the MySQL statement

For example 1


{dede:sql sql= ' select COUNT (*) as Nums from dede_addonarticle}
[Field:name = "nums"/]
{/dede:sql}
The output is the value of the Nums field of the Dede_addonarticle table, the query out a few to output several times

For example 2

{dede:sql sql= "select * from Dede_archives WHERE writer=~writer~"}
[Field:id/]
{/dede:sql}

Description: ~writer~ is a variable. For example, in the Content page template, the call is a table, a table has the field writer=xc, then the above statement in this content page templates is equivalent to select * from dede_archives where writer= ' xc ', [Field:id/] Is the ID field in the database dede_archives

Related Article

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.