ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

PHP for loop with EE {if}

May 03, 2011 1:35pm

Subscribe [2]
  • #1 / May 03, 2011 1:35pm

    pcm

    17 posts

    Hello,

    I’m a bit of a newbie and stuck on the approach/syntax of how to do something pretty simple. I have a PHP for loop creating a bunch of options for a form drop-down. I cannot figure out how to either pull in the i iteration or get the right syntax to make this work inside an EE {if} statement.

    I know it’s simple! Anyone point me in the right direction? Better way to approach this?

    <select name="bday_y">
    
        <option value="" disabled>Year</option>
        <?php $date = date("Y");
        for($i=$date-18;$i>$date-100;$i--){
        echo '<option value="'.$i.'" {if bday_y == $i }selected="selected"{/if}> '.$i.' </option> ';
        }
        ?>
    
    </select>

    I know the main issue is with:

    {if bday_y == $i }

    I’ve tested everything else and it’s all working fine otherwise—just not pulling the $i inside the EE code!

  • #2 / May 03, 2011 4:29pm

    glenndavisgroup

    436 posts

  • #3 / May 03, 2011 8:52pm

    pcm

    17 posts

    Thanks—this wasn’t the issue (it was just the syntax), but this was an important thing to know about as well!

  • #4 / May 04, 2011 5:46am

    John Henry Donovan

    12339 posts

    Hi pcm,

    To confirm, you are up and running again after correcting syntax?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases