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>
Caridorc
28k7 gold badges54 silver badges137 bronze badges
asked Jun 16, 2011 at 10:08
\$\endgroup\$
2
  • \$\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\$ Commented Jun 16, 2011 at 10:55
  • \$\begingroup\$ Seperate your html from your login as much as possible! \$\endgroup\$ Commented Jul 20, 2011 at 17:36

1 Answer 1

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>
answered Jun 16, 2011 at 13:51
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.