\$\begingroup\$
\$\endgroup\$
2
<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 ? "< 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
-
\$\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– Fge2011年06月16日 10:55:04 +00:00Commented Jun 16, 2011 at 10:55
-
\$\begingroup\$ Seperate your html from your login as much as possible! \$\endgroup\$Kzqai– Kzqai2011年07月20日 17:36:50 +00:00Commented Jul 20, 2011 at 17:36
1 Answer 1
\$\begingroup\$
\$\endgroup\$
Two advices:
-
When mixing HTML and PHP, it is a good practice to use PHP alternative syntax:
<?php for ($i = 1; $i <= 3; $i++): ?> .. <?php endfor ?>
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 ? "< 2 Jah." : $j + "Jahre" ?></option>
<?php endfor ?>
</select>
</div>
<?php endfor ?>
<div class="boxclear"></div>
</div>
lang-php