2017-01-22 1 views
0

Ich versuche, einen Bootstrap 3 Spalten mit 12 Zeilen mit folgenden php for Schleife zu erstellen. Aber es zeigt alle Daten in einer Spalte. Wie kann ich diese for Schleife Ergebnis in Bootstrap 3 Spalten (Col-MD-4) machen?Wie div mit Klasse nach 12 Schleife mit PHP hinzufügen?

Php For-Schleife:

<?php 
    for ($x = 1; $x <= 36; $x++) { 
     if($x % 12 == 0 || $x == 1) { 
      echo "<div class='col-md-4'>"; 
     } 
    ?> 
     <div class="checkbox form-inline"> 
      <label><input type="checkbox" name="ch_name[]" value="ch<?php echo $x; ?>">CH<?php echo $x; ?></label> 
      <input type="text" name="ch_for[]" value="" placeholder="Channel details" class="form-control ch_for"> 
     </div> 

     <?php if($x % 12 == 0) { 
      echo "</div>"; 
     } 
    } 
?> 

Antwort

2

Proper-Code ist:

<?php 
    for ($x = 1; $x <= 36; $x++) { 
     // proper condition 
     if($x % 12 == 1) { 
      echo "<div class='col-md-4'>"; 
     } 
    ?> 
     <div class="checkbox form-inline"> 
      <label><input type="checkbox" name="ch_name[]" value="ch<?php echo $x; ?>">CH<?php echo $x; ?></label> 
      <input type="text" name="ch_for[]" value="" placeholder="Channel details" class="form-control ch_for"> 
     </div> 

     <?php if($x % 12 == 0) { 
      echo "</div>"; 
     } 
    } 
?> 
+0

Ich brauche mehr Mathematik zu lernen :( –

Verwandte Themen