我想使用codeigniter在數據庫中提取數據。在數據庫中取數據的同時對錶進行編號
我爲每個數據生成一個錶行,並希望在實際數據描述之前編號。
這是我的看法: 請注意,<td>#</td>
的<tbody></tbody>
。那是我想要編號的地方。
<div class="table-responsive">
<table class="table table-hover table-bordered table-striped table-condensed">
<caption><h3><strong>Master List of Suppliers</strong></h3></caption>
<thead>
<tr>
<th>#</th>
<th>Supplier Code</th>
<th>Description</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<?php
foreach ($view_masterlist_suppliers as $row) {
echo
'<tr>
<td>#</td>
<td><a href="'.site_url("site/itemspersupplier?i=".$row->SUP_CODE).'">'.$row->SUP_CODE.'</a></td>
<td>'.$row->SUP_DESC.'</td>';
if(empty($row->SUP_ADD1)){ echo '<td><strong>- NO ADDRESS HAS BEEN ENCODED -</strong></td>';}
else if(empty($row->SUP_ADD2)){ echo '<td>'.$row->SUP_ADD1.'</td>';}
else{ echo '<td>'.$row->SUP_ADD1.', '.$row->SUP_ADD2.'</td>';}
echo '</tr>';
}
?>
</tbody>
</table>
</div>
這是我的控制器:
public function itemspersupplier(){
$data["title"] = "Supplier Master List";
$i = $_GET['i'];
$this->load->model("get_model");
$data["view_items_per_suppliers"] = $this->get_model->view_items_per_suppliers($i);
$this->load->view("templates/header", $data);
$this->load->view("templates/nav", $data);
$this->load->view("pages/items_per_supplier", $data);
$this->load->view("templates/footer", $data); }
這是我的模型:注:我有數據庫,但沒有什麼可擔心的吧:)
function view_items_per_suppliers($i){
//Load db2 and run query
$CI = &get_instance();
//Seeting the second parameter to TRUE (Boolean) the function will
//return the database object.
$this->db2 = $CI->load->database('db2', TRUE);
$this->db2->select('TBL_SUPPLIER.SUP_CODE,TBL_SUPPLIER.SUP_DESC,TBL_SUPPLIER.SUP_ADD1,TBL_SUPPLIER.SUP_ADD2,TBL_SUPPLIER.SUP_TEL1,TBL_SUPPLIER.SUP_TEL2,TBL_SUPPLIER.SUP_FAX1,TBL_SUPPLIER.SUP_FAX2,TBL_SUPPLIER.SUP_CONT,TBL_MASTER_ITEMS.IN_CODE,TBL_MASTER_ITEMS.ITE_DESC,TBL_MASTER_ITEMS.UNIT,TBL_MASTER_ITEMS.UNT_COST');
$this->db2->from('TBL_SUPPLIER');
$this->db2->join('TBL_MASTER_ITEMS', 'TBL_SUPPLIER.SUP_CODE = TBL_MASTER_ITEMS.SUP_CODE', 'inner');
$this->db2->where('TBL_MASTER_ITEMS.SUP_CODE', $_GET['i']);
//$this->db->limit('25');
$view_items_per_suppliers = $this->db2->get();
return $view_items_per_suppliers->result();
}
感謝。
謝謝,這是工作....太棒了! – Markmeplease