gpt4 book ai didi

php - 在数据库中获取的数据旁边对表进行编号

转载 作者:可可西里 更新时间:2023-11-01 08:29:51 25 4
gpt4 key购买 nike

我想使用 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>

这是我的 Controller :

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();
}

谢谢。

最佳答案

你可以使用任何人

 foreach ($view_masterlist_suppliers as $index=>$row) {
echo
'<tr>
<td>'.$index+1.'</td>
//your rest code

或者

    $index=0;
foreach ($view_masterlist_suppliers as $index=>$row) {
echo
'<tr>
<td>'.++$index.'</td>
//your rest code

关于php - 在数据库中获取的数据旁边对表进行编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29983069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com