2013-06-03 16 views
0

我想要做的是在2或3表列單獨的數據PHP的foreach單獨的表列中的多個數據

這裏是我的代碼,但現在我的代碼只顯示在一列

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

什麼其實我是想顯示的,但截圖的數據只是一個樣本,實際上是2個數據是不同的

enter image description here

+0

所以,你想要做1個MySQL查詢將返回3列,你想使3複選框列出來的呢?你能詳細闡述一下你的問題嗎?對我來說,它似乎是一個簡單的HTML問題,因爲你目前正在問。或者你想分裂你當前的長結果到幾列 – Prix

+0

嗨,大獎賽,我想要做的是用1 MYSQL查詢分裂成多個列長結果 – Oscar

回答

2

你必須做這樣的事情:

<?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; ?> 
+0

感謝兄弟,它是爲我工作,你是救我的生命:) – Oscar

+0

你拯救我的生命:)哈哈 感謝您的代碼! – 2014-02-26 15:10:54