0
\$\begingroup\$
<div class="minipassbox" style="margin-top: 5px;">
               <?php
                   for($i = 1; $i <= 3; $i++) {
                      $marginRight = ($i < 3 ? "margin-right:4px" : "");
                      echo "<div style='width:56px;float:left;{$marginRight}'>";
                      echo "<label for='param_kind{$i}' style='padding-left:4px;'>{$i}. Kind</label>";
                      echo "<select id='param_kind{$i}' class='selFields' name='param_kind{$i}' style='margin-top:3px'>";
                      echo  "<option selected='' value='-1'>--- </option>";
                      for($j = 1; $j <= 16; $j++) {
                         $selected = ($oRecherche->getParamValue("param_kind{$i}") == $j ? "selected='selected'" : "");
                         $option_text = ($j == 1 ? "&lt; 2 Jah." : $j + "Jahre");
                         echo "<option value='{$j}' {$selected}>{$option_text}</option>";
                      }
                      echo "</select>";
                      echo "</div>";
                   }   
               ?>
               <div style="clear:left"></div>
            </div>
| improve this question | | | | |
\$\endgroup\$
  • \$\begingroup\$ Well, it's a loop. Any specific question? Beside, why don't you hard-code it if there isn't any dynamic in it? \$\endgroup\$ – Fge Jun 16 '11 at 10:55
  • \$\begingroup\$ Seperate your html from your login as much as possible! \$\endgroup\$ – Kzqai Jul 20 '11 at 17:36
4
\$\begingroup\$

Two advices:

  1. Use PHP alternative syntax

    When mixing HTML and PHP, it is a good practice to use PHP alternative syntax:

    <?php for ($i = 1; $i <= 3; $i++): ?>
    ..
    <?php endfor ?>
    
  2. Improve the HTML code

    • Use double quotes in tag attributes (HTML standard)
    • Try to respect indentation
    • Move style to css declarations

Final code proposition:

<style type="text/css">
  .minipassbox {
    margin-top: 5px;
  }
  .minipassbox > div {
    width: 56px;
    float: left;
  }
  .minipassbox > div.lt3 {
    margin-right: 4px;
  }
  .minipassbox label {
    padding-left: 4px;
  }
  .selFields {
    margin-top: 3px;
  }
  .boxclear {
    clear: left;
  }
</style>
<div class="minipassbox">
<?php for ($i = 1; $i <= 3; $i++): ?>
  <div <?php echo $i < 3 ? ' class="lt3"' : '' ?>
    <label for="param_kind<?php echo $i ?>"><?php echo $i ?>. Kind</label>
    <select id="param_kind<?php echo $i ?>" class="selFields" name="param_kind<?php echo $i ?>">
      <option value="-1">--- </option>
      <?php for ($j = 1; $j <= 16; $j++): ?>
      <option value=""<?php echo $j ?>"<?php echo $oRecherche->getParamValue("param_kind$i") == $j ? ' selected="selected"' : '' ?>><?php echo $j == 1 ? "&lt; 2 Jah." : $j + "Jahre" ?></option>
      <?php endfor ?>
    </select>
  </div>
<?php endfor ?>
  <div class="boxclear"></div>
</div>
| improve this answer | | | | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.