0

What I want to do is separate data in 2 or 3 table column

here is my code, but my code now is only display in one column

<?php if(isset($queue_record)) : foreach($queue_record as $row) : ?>

<tr>
<td>
<label class="checkbox ">
<input type="checkbox" name="check_queue[]" id="inlineCheckbox1"
          class="inlineCheckbox1" value="<?php echo $row->tenantqueueid; ?>">
          <?php echo $row->queuename; ?>
</label>
</td>
</tr>

<?php endforeach; ?>
<?php endif; ?>

What I actually want to display, but the screenshot data just a sample, actually the 2 column data are different

enter image description here

2
  • So you want to do 1 MySQL query that will return 3 columns and you would like to make 3 checkbox columns out of that ? can you elaborate more on your problem ? to me it seems a simple html issue as you are currently asking. Or you want to split your current long results into several columns Commented Jun 3, 2013 at 1:47
  • Hi Prix, what I want to do is with 1 MYSQL query split long result into several columns Commented Jun 3, 2013 at 1:56

1 Answer 1

2

You have to to do something like this:

<?php 
if(isset($queue_record)){
    echo "<table>";
    echo "<tr>";
    echo "<th>Column 1 Header</th>";
    echo "<th>Column 2 Header</th>";
    echo "<th>Column 3 Header</th>";
    echo "</tr>";

    $num_cols = 3; //We set the number of columns
    $current_col = 0;
foreach($queue_record as $row):
if($current_col == "0")echo "<tr>"; //Creates a new row if $curent_col equals to 0
?>
<td>
<label class="checkbox ">
<input type="checkbox" name="check_queue[]" id="inlineCheckbox1"
          class="inlineCheckbox1" value="<?php echo $row->tenantqueueid; ?>">
          <?php echo $row->queuename; ?>
</label>
</td>
<?php 
   if($current_col == $num_cols-1){ // Close the row if $current_col equals to 2 in the example ($num_cols -1)
       echo "</tr>";
       $current_col = 0;
   }else{
       $current_col++;
   }
endforeach;
echo "</table>";

<?php endif; ?>
Sign up to request clarification or add additional context in comments.

1 Comment

You are save my life as well :) haha Thanks for this code!

Your Answer

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.