Come on with PHP.

Source: Internet
Author: User
Come on with PHP. If ($ downhits = 2)
{
Echo'



{Loop $ downfile $ r}

  • {$ R}

  • {/Loop}
    {Loop $ downfiles $ r}
  • {$ R}

  • {/Loop}

    ';
    }
    Else
    {
    Echo'



    {Loop $ downfile $ r}

  • {$ R}

  • {/Loop}
    {Loop $ downfiles $ r}
  • {$ R}

  • {/Loop}

    ';}
    ?>

    The above code is output in echo, but this $ r and $ downfiles do not seem to respond, so I would like to ask how to output $ r and $ downfiles in echo, or how to call or use the syntax. right


    Reply to discussion (solution)

    First, variables in single quotes in PHP cannot be parsed as variable values.

    So replace your echo 'xxxxxxxxxxxxxxxxxx' with echo "xxxxxxxxxxx" (and replace the internal double quotation marks with single quotation marks)

    Secondly, I don't understand the environment in which such a statement is used. can it be a normal loop? the above method is only for the problem that the two variables you asked cannot be parsed.

    I do not understand php, but I know that variables are not included in single quotes. I only use the variable name as a string.

    The loop tag is a custom template loop tag of PHPcms. here, echo outputs the string to the template. the variable $ downfiles is allocated to the controller file corresponding to the template, loop then outputs the variable cyclically. $ downfiles is the value in the array $ r.

    If ($ downhits = 2)
    {
    Echo'

    ';

    {Loop $ downfile $ r}

  • {$ R}

  • {/Loop}
    {Loop $ downfiles $ r}
  • {$ R}

  • {/Loop}
    Echo'

    ';
    }
    Else
    {
    Echo'

    ';

    {Loop $ downfile $ r}

  • {$ R}

  • {/Loop}
    {Loop $ downfiles $ r}
  • {$ R}

  • {/Loop}
    Echo'

    ';}
    ?>

    Let's take a look at the template usage.

    Where did you write this section. Is it written in action or template.

    Didn't the landlord understand that programs and templates should be separated?

    You write an html template in the program and then include the template parameters. Now, your html is displayed, but your original template is displayed and has been sent to the client, but do you still want the customer segment to explain your code like {loop} {/loop? You are not writing js.

    A template has a specific template function to process it. In the end, it will be interpreted as php code on the server side for execution. Therefore, do not write template code in the program.

    We recommend that you. You can pass the value $ downhits to the template.
    Then write in the template:

    {if $downhits==2}

    {loop $downfile $r}

  • {$r}
  • {/loop}{loop $downfiles $r}
  • {$r}
  • {/loop}

    {else}

    {loop $downfile $r}

  • {$r}
  • {/loop} {loop $downfiles $r}
  • {$r}
  • {/loop}

    {/if}


    Or you can write it directly in the php program as follows:
    if($downhits==2){$html='

    ';foreach($downfile as $r){$html.='

  • '.$r.'
  • ';}foreach($downfiles as $r){$html.='
  • '.$r.'
  • ';}$html.='

    ';}else{$html='

    ';foreach($downfile as $r){$html.='

  • '.$r.'
  • ';}foreach($downfiles as $r){$html.='
  • '.$r.'
  • ';}$html.='

    ';}

    In addition, the p tag directly contains the li tag, as if it was not written in html...

    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.