dongpengyu1363 2013-01-08 12:48
浏览 26

codeigniter分页库中表的序列号

I have problems when numbering the tables using CodeIgniter framework with libraary pagination. below are the table..

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

the issue is on the next page in the table below..

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

I want the next page numbering sequential numbering starting from the end of the previous value. Supposedly in figure 2 numbering number "2" instead of "1".

code in the controller:

$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);

and code in my Model :

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

and this code in view :

<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>

I hope someone can help me on this issue .. thanks

  • 写回答

3条回答 默认 最新

  • douchongzhang9267 2013-05-20 05:39
    关注

    before foreach you have to add

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

    No NIP Name Category Attachment Type Attachment Page

            </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>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度