0

使用带有库分页的 CodeIgniter 框架对表进行编号时遇到问题。下面是表格。。

+------------------------------------------+
| num| NIP    | Name   | Category  | Type  |
+------------------------------------------+
| 1  | 12345  | udin   | A         |  A1   |
+------------------------------------------+
|    |        |        | B         |  B1   |
+------------------------------------------+
|    |        |        | C         |  C1   |
+------------------------------------------+
| 2  | 54321  | JHON   | B         |  B2   |
+------------------------------------------+
|    |        |        | C         |  C1   |
+------------------------------------------+

问题在下表的下一页。

+------------------------------------------+
| num| NIP    | Name   | Category  | Type  |
+------------------------------------------+
| 1  | 54321  | JHON   | F         |  F2   |
+------------------------------------------+
|    |        |        | G         |  G3   |
+------------------------------------------+
|    |        |        | G         |  G4   |
+------------------------------------------+
|    |        |        | I         |  I3   |
+------------------------------------------+
|    |        |        | J         |  J1   |
+------------------------------------------+

我想要从前一个值的末尾开始的下一页编号顺序编号。假设在图 2 中编号为“2”而不是“1”。

控制器中的代码:

$this->load->library('pagination');
$data['judul'] = 'Report Data Attachment';
$start_row = $this->uri->segment(3);
$per_page = 10; 

        if (trim($this->uri->segment(3)) == '')
        {
            $start_row = '0';
        }
    $config['base_url'] = base_url().'report/index/';
    $config['total_rows'] = $this->lampiran_m->lampiran_karyawan_semua_page_conter()->num_rows();
    //$config['uri_segment'] = '3';
    $config['per_page'] = $per_page;
    $config['full_tag_open'] = '<p class="page">';
    $config['full_tag_close'] = '</p>';       
      $this->pagination->initialize($config);
    $data['pagination'] = $this->pagination->create_links();
     $data['lampiran'] = $this->lampiran_m->lampiran_karyawan_semua_page($start_row,','.$per_page);



        $data['no'] = '';
     $data['last'] = '';

     $this->template->display('tabel_report',$data);

和我的模型中的代码:

public function lampiran_karyawan_semua_page($offset='',$limit='')
{
    $qry = "select distinct lampiran.id_category,name_category,tipe,lampiran.nip from lampiran
    left join employee on (lampiran.nip = employee.nip)
    left join category on (lampiran.id_category=category.id_category) where lampiran.id_category = category.id_category and lampiran.nip=employee.nip  order by lampiran.nip desc limit $offset $limit";
    return $this->db->query($qry);
}

并查看此代码:

<table border="1" width="100%" cellpadding="0" cellspacing="0" id="product-table" >
            <tr>
            <th class="table-header-repeat line-left minwidth-1"> <a href="#mainform">No</a></th>
                <th class="table-header-repeat line-left minwidth-1"> <a href="#mainform">NIP</a></th>
                <th class="table-header-repeat line-left minwidth-1"> <a href="#mainform">Name</a></th>
                <th class="table-header-repeat line-left minwidth-1"> <a href="#mainform">Category Attachment</a></th>
                <th class="table-header-repeat line-left minwidth-1"><a href="#mainform">Type Attachment</a>    </th>
                <th class="table-header-repeat line-left minwidth-1"><a href="#mainform">Page</a>   </th>

            </tr>
            <?php 


                    foreach($lampiran->result_array() as  $k) {

             $now=$k['nip'];
              if($last!=$now )  {
                $no++;
              echo "<tr><td>$no</td><td>$k[nip]</td><td>".$this->employee_m->get($k['nip'])->nama."</td><td>$k[name_category]</td><td>$k[tipe]</td><td>"; ?>
              <?php foreach($this->lampiran_m->conter_tabel_semua($k['id_category'],$k['tipe'],$k['nip'])->result() as $row) :?>
                        <?php echo $row->nilai;?>
                    <?php endforeach; 
              echo "</td></tr>";

              }else{

              echo "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>$k[name_category]</td><td>$k[tipe]</td><td>"; ?>
              <?php foreach($this->lampiran_m->conter_tabel_semua($k['id_category'],$k['tipe'],$k['nip'])->result() as $row) :?>
                        <?php echo $row->nilai;?>
                    <?php endforeach; 
              echo "</td></tr>";
              }
             $last = $k['nip'];

             }
            ?>
           <tr><td colspan="5" style="text-align: center;"><b>Jumlah Total</b></td><td>
                <?php foreach($this->lampiran_m->jumlah_semua_lampiran()->result() as $row) :?>
                        <?php echo "<b>$row->jumlah</b>";?>
                    <?php endforeach; ?>
           </td></tr>

            </table>

我希望有人可以在这个问题上帮助我..谢谢

4

3 回答 3

3

在 foreach 你必须添加

$no = $this->uri->segment(3)+1;

无 NIP 名称 类别 附件类型 附件页

        </tr>
        <?php 

            //before foreach you have to add 
            $no = $this->uri->segment(3)+1;
                foreach($lampiran->result_array() as  $k) {

         $now=$k['nip'];
          if($last!=$now )  {
            $no++; 
          echo "<tr><td>$no</td><td>$k[nip]</td><td>".$this->employee_m->get($k['nip'])->nama."</td><td>$k[name_category]</td><td>$k[tipe]</td><td>"; ?>
          <?php foreach($this->lampiran_m->conter_tabel_semua($k['id_category'],$k['tipe'],$k['nip'])->result() as $row) :?>
                    <?php echo $row->nilai;?>
                <?php endforeach; 
          echo "</td></tr>";

          }else{

          echo "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>$k[name_category]</td><td>$k[tipe]</td><td>"; ?>
          <?php foreach($this->lampiran_m->conter_tabel_semua($k['id_category'],$k['tipe'],$k['nip'])->result() as $row) :?>
                    <?php echo $row->nilai;?>
                <?php endforeach; 
          echo "</td></tr>";
          }
         $last = $k['nip'];

         }
        ?>
       <tr><td colspan="5" style="text-align: center;"><b>Jumlah Total</b></td><td>
            <?php foreach($this->lampiran_m->jumlah_semua_lampiran()->result() as $row) :?>
                    <?php echo "<b>$row->jumlah</b>";?>
                <?php endforeach; ?>
       </td></tr>

        </table>
于 2013-05-20T05:39:20.710 回答
2

请在 foreach 语句之前添加以下行

$currentffset = ($this->uri->segment(3)) ?$this->uri->segment(3) : 0;
$slno_start = (($currentffset / $per_page) * per_page) + 1;

之后,在 foreach 的最后一行使用 $slno_start 作为 foreach 中每个项目的序列号,只需递增它

$slno_start++;
于 2014-02-26T05:09:20.437 回答
1

上述答案的微小改进。谢谢你们俩

$count =$this->uri->segment(3)+1;
foreach($records as $rec){echo $count; $count++;}
于 2015-02-02T07:21:41.550 回答