Welcome Guest, Not a member yet? Register   Sign In
Codigniter grouping in views
#4

If you are using your original array something like this would work:

PHP Code:
<?php if ( ! empty($questions)) { ?>

    <?php $first_question TRUE?>
    <?php $current_question 0?>
    
    <?php foreach ($questions as $question) { ?>

        <!-- Is this a new question? -->
        <?php if ($question['question_id'] != $current_question) { ?>
        
            <!-- are we closing a previous question panel? -->
            <?php if ( ! $first_question) { ?>
                </div> <!-- close panel body -->
                </div> <!-- close panel -->
            <?php } else { ?>
                <?php $first_question FALSE?>
            <?php ?>
            
            <!-- set current quesiton id, so title does not show for each choice -->
            <?php $current_question $question['question_id']; ?>
            
            <!-- show current question -->
            <div class="panel panel-default">
                <div class="panel-heading">
                    <?php echo $question['question_title']; ?>
                </div>
                <div class="panel-body">

        <?php ?>
            
        <?php // show choices title ?>
        <?php echo $question['choices_title']; ?>

    <?php ?>
    
    <!-- closing last question panel -->
    </div><!-- close panel body -->
    </div><!-- close panel -->
    
<?php ?>
Reply


Messages In This Thread
RE: Codigniter grouping in views - by PaulD - 10-28-2017, 07:56 AM
RE: Codigniter grouping in views - by PaulD - 10-29-2017, 04:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB