0

I am trying to create a bootstrap 3 columns with 12 rows using following php for loop. But it's showing all the data in one column. How can I make this for loop result in bootstrap 3 columns ( col-md-4 ) ?

Php For Loop:

<?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>";
        }
    }
?>

1 Answer 1

1

Proper code is:

<?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>";
        }
    }
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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