php - 我必须显示一个新字段计数。这是 jil_mrorfq 表中每个需求 id 的计数

标签 php mysql codeigniter codeigniter-2 codeigniter-3

我有一个分页管理页面,其中包含需求服务、发布者、管理者、数量、发布于、表需求中的状态等字段。我必须显示一个新的归档计数。即 jil_mrorfq 表中每个需求 id 的计数。 我完成了管理部分。但我不知道如何显示计数,如何与此代码一起获取。任何人都知道查询,请帮助我完成此任务。 我正确地完成了分页管理页面。但是每个需求 ID 的计数必须显示为表中的下一个字段。我完全困惑它如何获取。查询将如何编写。有人知道答案,那么请帮助我完成这个任务。

我的 Controller

public function managerequirement() {
        $this->load->helper(array('form', 'url'));
        $this->load->view('moderator/templates/header');
        $this->load->view('moderator/templates/sidebar');
        $this->load->library('pagination');
        $config = array();
        $config["base_url"] = base_url() . "moderator/Requirement/managerequirement";
        $config["total_rows"] = $this->requirement_model->record_count();
        $config["per_page"] = 20;
        $config["uri_segment"] = 4;
        $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['first_link'] = 'first';
        $config['last_link'] = 'last';
        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';
        $config['prev_link'] = '&laquo';
        $config['prev_tag_open'] = '<li class="prev">';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&raquo';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(4)) ? $this->uri->segment(4) :0;
        $data["results"]= $this->requirement_model->
                fetch_data($config["per_page"], $page); 
        $data["links"] = $this->pagination->create_links();
        $this->load->view('moderator/managerequirement', $data);
        $this->load->view('moderator/templates/footer');
    }

我的模型

 public function fetch_data($limit, $start) {
        $this->db->limit($limit, $start);
         $this->db->from('jil_requirements');
          $this->db->join('jil_users', 'jil_requirements.rqm_userid=jil_users.usr_id', 'left');
           $this->db->join('jil_merchants', 'jil_requirements.rqm_createdempid=jil_merchants.mer_id', 'left');
           $this->db->where('jil_requirements.rqm_permission!=', '4');
        $query =  $this->db->get();  
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                 $data[] = $row;
            }
           return $data;
        }
        return false;
   }

查看

 <div class="col-xs-12">

                                <table class="table table-bordered table-hover table-striped">
                                    <tr role="row">
                                        <th class="sorting" width="5%">#</th>
                                        <th class="sorting" width="30%">Requirement Service</th>
                                        <th class="sorting" width="10%">Posted By</th>
                                        <th class="sorting" width="10%">Managed By</th>
                                         <th class="sorting" width="15%">Quantity</th>
                                        <th class="sorting" width="15%">Posted  On</th>

                                        <th class="sorting" width="15%">Status</th>


                                    </tr>

                                    <?php
                                     if(!empty($results))
                                    {
                                    foreach ($results as $row) {
                                        ?><tr>  
                                            <td class=" "><?php echo $row->rqm_id; ?></td>  
                                            <td class=" ">   <a href="<?php echo base_url() . 'moderator/Requirement/viewrequirementdetails/' . $row->rqm_id ?>"><?php echo $row->rqm_service; ?></a></td>
                                           <td class=" "><?php
                                           echo $row->usr_name;

                                           ?></td>  
                                           <td class=" "><?php
                                           echo $row->mer_name;

                                           ?></td>  
                                             <td class=" "><?php
                                           echo $row->rqm_quantity;

                                           ?></td>  
                                             <td class=" "><?php echo date('d-M-Y',$row->rqm_dated);?></td>  
                                             <td class=" "><?php 
                                             if($row->rqm_permission=='0')
                                             {
                                                 echo "In-Active";

                                             }
                                            else if($row->rqm_permission=='1')
                                             {
                                                 echo "Active";

                                             }
                                               else if($row->rqm_permission=='2')
                                             {
                                                 echo "Pending";

                                             }
                                               else if($row->rqm_permission=='3')
                                             {
                                                 echo "Suspend";

                                             }
                                               else if($row->rqm_permission=='4')
                                             {
                                                 echo "Delete";

                                             }
                                             ?></td>  

                                        </tr>  
                                    <?php }
                                    }
                                    ?>  

                                </table>

                                <?php echo $links; ?>   
                            </div> 

最佳答案

使用下面的代码

  public function fetch_data($limit, $start) {
      $this->db->limit($limit, $start);
      $this->db->from('jil_requirements');
      $this->db->join('jil_users', 'jil_requirements.rqm_userid=jil_users.usr_id', 'left');
      $this->db->join('jil_merchants', 'jil_requirements.rqm_createdempid=jil_merchants.mer_id', 'left');
      $this->db->where('jil_requirements.rqm_permission!=', '4');
      $query =  $this->db->get();  
      if ($query->num_rows() > 0) {
      foreach ($query->result() as $row) {
          $this->db->select('count(jil_mrorfq.rfq_requirementid) as total'); 
          $this->db->from('jil_mrorfq'); 
          $this->db->where('jil_mrorfq.rfq_requirementid',$row->rqm_id);
          $this->db->group_by('jil_mrorfq.rfq_requirementid'); 
          $query2= $this->db->get()->row_object();

         $row->total_count = $query2->total;
         $data[] = $row;
                }
               return $data;
            }
            return false;
       }

关于php - 我必须显示一个新字段计数。这是 jil_mrorfq 表中每个需求 id 的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34986387/

相关文章:

javascript - 打开一个模态(在 Codeigniter 中),从依赖于 php var 的 URL 加载(在 iframe 中)内容

php - 显示表格并提供删除选项

mysql - 如何找到下一个免费的唯一 4 位数号码

mysql - 如何在涉及 CONCAT 的 cakephp 3 中进行查询

php - 函数在 mysql 中显示数据截断列的警告

php - CodeIgniter:从所有文件夹中删除 index.html 是否安全?

php - 如何在codeigniter中从另一个 Controller 加载 Controller ?

javascript - 创建一个 session 以不再在投票中投票

php - Codeigniter模型函数从mysql获取数据

php - Laravel - 多个具有相同名称的 Controller