Guide to Using php Statements in dedecms

  • 2021-08-03 09:24:28
  • OfStack

In DEDECMS, if you use the php statement, you have a {dede: php} tag that you can use. The simplest input is as follows


{dede:php}    $numA = 1;    $numB = 2;    echo $numA + $numB; {/dede:php}

It can be seen from the above statement that the dede: php tag can be used as 1 in php, and the above statement is written as follows in php

 
<?
$numA=1;
$numB=2;
echo $numA+$numB;
?>

Does it look very similar? Look at another one with if else condition judgment


[field:global runphp='yes' name=autoindex]
$a="<SPAN class='num active'>";
$b="</SPAN>";
$c="<(www.ofstack.com)SPAN class='num'>";
if (@me > 3) @me = $c.@me.$b;
else @me = $a.@me.$b;
[/field:global]

I won't write this in php. Next, we will look at the use of dede php tags combined with sql tags.

Output a single content in combination with SQL query


{dede:php}
$row = $dsql->GetOne('select id,typename from dede_arctype where id=2');
print_r($row);
{/dede:php}

The content of this output is


Array
(
[id] => 2
[typename] => Question and answer
)

Isn't it very simple? Friends who need to learn can refer to this article.


Related articles: