Php 如何获得codeigniter中每个函数的2个序列号的值?
我的代码有问题,因为我使用嵌套的foreach从数据库中获取一些值。 我需要得到表中序列号的值 我使用以下代码:Php 如何获得codeigniter中每个函数的2个序列号的值?,php,mysql,codeigniter,nested-loops,html2pdf,Php,Mysql,Codeigniter,Nested Loops,Html2pdf,我的代码有问题,因为我使用嵌套的foreach从数据库中获取一些值。 我需要得到表中序列号的值 我使用以下代码: $TipeIklan = $this->input->post('inputTipeIklan'); $ProdukCode = $this->input->post('inputPtodukCode'); $Date = $this->input->post('inpu
$TipeIklan = $this->input->post('inputTipeIklan');
$ProdukCode = $this->input->post('inputPtodukCode');
$Date = $this->input->post('inputDate');
$WherCustomer = array("CustomerCode >=" => $Customer1,
"CustomerCode <=" => $Customer2);
$ArrCustomer = $this->customer_m->order_by("CustomerCode","ASC")->get_many_by($WherCustomer);
if($ArrCustomer){
foreach($ArrCustomer as $item_customer){
$Kwitansi = $this->kwitansi_m->getUmurPiutang($item_customer->CustomerCode,$ProdukCode,$Date);
if($Kwitansi){
$content .='
<tr>
<td class="fontB" colspan="17">'.$item_customer->CustomerCode.'</td>
</tr>';
foreach($Kwitansi as $item){
$n = count($Kwitansi);
$no = $n;
$content .='
<tr>
<td class="font" width="200">'.$no.'</td>
</tr>';
$n++;
} ### end of foreach $Kwitansi as $item ###
} ### end of $Kwitansi ###
} ### end of foreach $ArrCustomer as $item_customer ###
} ### end of $ArrCustomer ###
$TipeIklan=$this->input->post('inputTipeIklan');
$ProdukCode=$this->input->post('inputPtodukCode');
$Date=$this->input->post('inputDate');
$WherCustomer=数组(“CustomerCode>=”=>$Customer1,
“CustomerCode更改您的代码
foreach($Kwitansi as $item){
$n = count($Kwitansi);
$no = $n;
$content .='
<tr>
<td class="font" width="200">'.$no.'</td>
</tr>';
$n++;
foreach($Kwitansi作为$item){
$n=计数($Kwitansi);
$no=$n;
$content.='
“.$否”
';
$n++;
}
到
$m=0;
foreach($Kwitansi作为$item){
$n=$m+1;
$content.='
“.$否”
';
$n++;
$m++;
}
$n=count($Kwitansi);这是错误的,因为如果你得到了5个count,那么就从5,6,7…n开始。所以,你需要在循环之前加上$n=1,以1,2…开始,依此类推
我不确定这是否是您想要的,但是否要按顺序显示项目的编号
说,
客户X
1) 项目A
客户Y
2) B项
3) 项目C
客户Z
4) D项
如果是:
然后在$ArrCustomer foreach之前初始化计数器,并在$kwitasi foreach内递增计数器。
$TipeIklan=$this->input->post('inputTipeIklan');
$ProdukCode=$this->input->post('inputPtodukCode');
$Date=$this->input->post('inputDate');
$WherCustomer=数组(“CustomerCode>=”=>$Customer1,
"CustomerCode你想按发票编号排序吗?@KamleshSolanki不,我只想从1、2、3开始,在我的例子中,我得到了序列号,但如果客户代码不同,它总是从1开始。请阅读:它仍然是一样的,我添加类似这样的内容$m=0;$n=$m+1;在每张发票结束之前,我添加,$n++;$m++;其工作感谢您回答我的问题,为什么您需要添加更多的变量,如$MBE,因为它使用两个foreach,就像以前如何创建这样的数字?1 12 123 1234 12345其使用两个变量这是我想要的,我只需要发票表中的编号项,其中客户代码在发票表中可用,请看m我之前对@Kamlesh Solankii的评论是我自己解决这个问题的,但是谢谢你给我一个评论
$m = 0;
foreach($Kwitansi as $item){
$n = $m+1;
$content .='
<tr>
<td class="font" width="200">'.$no.'</td>
</tr>';
$n++;
$m++;
}
$n = count($Kwitansi); this wrong because of if you got 5 count then start with 5,6,7...n. So, you need to put before loop and assign $n=1 to start with 1,2 .... so on
$TipeIklan = $this->input->post('inputTipeIklan');
$ProdukCode = $this->input->post('inputPtodukCode');
$Date = $this->input->post('inputDate');
$WherCustomer = array("CustomerCode >=" => $Customer1,
"CustomerCode <=" => $Customer2);
$ArrCustomer = $this->customer_m->order_by("CustomerCode","ASC")->get_many_by($WherCustomer);
$n = 1; // counter that never gets reset.
if($ArrCustomer){
foreach($ArrCustomer as $item_customer){
$Kwitansi = $this->kwitansi_m->getUmurPiutang($item_customer->CustomerCode,$ProdukCode,$Date);
if($Kwitansi){
$content .='
<tr>
<td class="fontB" colspan="17">'.$item_customer->CustomerCode.'</td>
</tr>';
foreach($Kwitansi as $item){
$no = $n;
$content .='
<tr>
<td class="font" width="200">'.$no.'</td>
</tr>';
$n++;
} ### end of foreach $Kwitansi as $item ###
} ### end of $Kwitansi ###
} ### end of foreach $ArrCustomer as $item_customer ###
} ### end of $ArrCustomer ###