2014-08-29 43 views
-2

我對codeigniter的視圖有問題。如何在視圖中使用codeigniter使用foreach

我想保留標題。

示例:標題包含視圖的主標題,如產品編號,產品種類和產品數量。以下是所有可用產品的列表。

我想嘗試編碼,但它會重複產品編號,產品種類和產品數量的頂部標題。

結果應該是這樣的。

Product number: 0011 
Product Kind: Beverages 
Product Quantity: 1000 
-------------------------- 
Fit n Right 
Coke 
Pepsi 
Lemon Juice 
Gatorade 
etc... 

something like that. But my output code was: 

Product number: 0011 
Product Kind: Beverages 
Product Quantity: 1000 
-------------------------- 
Fit n Right 

Product number: 0011 
Product Kind: Beverages 
Product Quantity: 1000 
-------------------------- 
Coke 

Product number: 0011 
Product Kind: Beverages 
Product Quantity: 1000 
-------------------------- 
Pepsi 

Product number: 0011 
Product Kind: Beverages 
Product Quantity: 1000 
-------------------------- 
Lemon Juice 

等等...

我的代碼:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
     <title>Beverages</title> 
</head> 
<body> 
<?php 

$funds=strtoupper($fundagent); 

    if ($eid_num >0){ 
     foreach($eid_num as $row): 
      $eid=$row->eid; 
      $eseries=$row->becno; 
      $amount=$row->amount; 
      $rescenter=$row->res_center; 

?> 
<div id="entrystyle" align="center"> 
table class="box-table-a" valign="top"> 
    <thead> 
    <tr> 
     <th colspan="7">Control System</th> 
    </tr> 
    </thead> 
<?php 
    echo form_open('/beverage/update-data-entry/'.$eid.'/'.strtolower($eseries)); 
?> 
<tr class="gb"> 
    <td id="fontstyle"> 
      <label>Budget Earmarking Control No.</label> 
      <input type="text" name="becno" id="controlno" size="15" required="required" value="<?php echo $eseries; ?>" onblur="copy_control_no()" readonly="readonly" /> 
    </td> 
    <td id="fontstyle"> 
     <label>Amount</label> 
     <input type="text" name="amount" id="amount" size="15" required="required" value="<?php echo $amount; ?>" readonly="readonly"> 
    </td>` 

這部分我想重複或循環

`<td id="fontstyle"> 
     <label>Responsibility Center</label> 
     <input type="text" name="responsible" id="responsible" size="15" required="required" value="<?php echo $rescenter; ?>" readonly="readonly"> 
    </td> 
</tr> 
</table> 

<?php endforeach; ?> 

</table> 
</div> 

</body> 
</html> 
+0

能否請您分享一些代碼ü寫什麼呢? – Naincy 2014-08-29 07:11:52

+0

請張貼一些代碼..或至少發佈變量(數組),你得到 – Saswat 2014-08-29 07:21:25

回答

-1

控制器:

public function func(){ 
    ....... 
    $data['result'] = $this->model->myfunction(); // return resultset from DB 
    $this->load->view('folder/filename', $data); 
    ........ 
} 

查看:

<?php 
foreach($result as $value) 
{ 
    echo $value.'<br/>'; 
} 

?> 

我想你會從中得到一些想法。

+0

是的,這就是我正在使用,但該代碼重複標題標題,我希望它會顯示標題標題這也是從數據庫和下面是列表。 – user2609962 2014-08-29 07:31:26

+0

請張貼一些代碼,然後我們可以提供幫助 – Naincy 2014-08-29 08:43:10

0

試試這個

function build_view($flake) { 
     $this->data['content'] = $this->load->view($flake, $this->data, TRUE); 
     $this->load->view('header', $this->data); 
    } 
相關問題