使用codeigniter查找子类别下的已发布要求

时间:2016-06-15 08:47:00

标签: php codeigniter model codeigniter-2

我有三张牌桌:jil_requirementbriefjil_requirementdetailjil_category. 表结构:

jil_requirementbrief:

 rqm_id,
    rqm_category,
    rqm_cusreference,
    rqm_manufacturer,
    rqm_productgroup,
    rqm_exdate,
    rqm_permission,
    rqm_managedby,
    rqm_dated

jil_requirementdetail:

rqmd_rqmid,rqmd_title,rqmd_requirements,rqmd_quantity,rqmd_unit.

jil_category:

ctg_id,ctg_name,parent_id

当我们发布需求时,会选择类别和子类别并将其插入jil_requirementbrief table。详细信息存储在详细信息表中。我写了一个代码来生成pdf。当我们从下拉列表中选择包含日期的父类别时,在该日期内发布的需求将生成为pdf

我目前的问题是。

例如:如果我选择了名为“材料”的类别,则有材料的子类别,如铝,钢等。

jil_requirementbrief table中,rqm_category是主要类别ID,rqm_productgroup是子类别ID。

我希望pdf中的结果如此。

如果我从下拉列表中选择了“材料”类别,那么生成的pdf数据将如下所示:

steel

 Serial No    Req.ID     Title    Quantity   Unit     Managed By

   1           3          ttt    6          tons      gowtham

   2            3         ttt    6          tons      gowtham

Aluminium

 Serial No  Req.ID  Title  Quantity  Unit    Managed By

   1         4       yy    6          tons   tom

   2         5       uuu    6          tons   tom

我的控制器

public function purchase_request() {
        $this->load->helper(array('form', 'url'));
        $cat_id = $this->input->post('category');
        $start_date = strtotime($this->input->post('StartDate'));
        $end_date = strtotime($this->input->post('EndDate'). ' +1 day');
        $end_date1 = strtotime($this->input->post('EndDate'));
        $data['user_data'] = $this->requirement_model->get_data_print($cat_id,$start_date,$end_date);


         $data['startdate']=$start_date;
          $data['enddate']=  $end_date1;    

        $this->load->library('M_pdf');
        if (function_exists("set_time_limit") == TRUE AND @ ini_get("safe_mode") == 0) {
            @set_time_limit(300);
        }
        $html = $this->load->view('moderator/print_purchaserequest', $data, true);
        $this->m_pdf->pdf->setTitle('Purchase Request Sheet');
        $this->m_pdf->pdf->WriteHTML($html);
        $this->m_pdf->pdf->Output('Sales_Log.pdf', "I");
    }

我的模特

public function get_data_print($cat_id, $start, $end) {
        $this->db->select('*');
        $this->db->from('jil_requirementbrief');
        $this->db->join('jil_requirementdetail', 'jil_requirementdetail.rqmd_rqmid=jil_requirementbrief.rqm_id', 'left');
           $this->db->join('jil_requnits', 'jil_requnits.id=jil_requirementdetail.rqmd_unit', 'left');
         $this->db->join('jil_employees', 'jil_employees.emp_id=jil_requirementbrief.rqm_managedby', 'left');
         $this->db->order_by('jil_requirementdetail.rqmd_title','ASC');
        $this->db->where('jil_requirementbrief.rqm_category', $cat_id);
        $this->db->where('jil_requirementbrief.rqm_dated >=', $start);
        $this->db->where('jil_requirementbrief.rqm_dated <=', $end);
        $this->db->where('jil_requirementbrief.rqm_permission!=4');
        $query = $this->db->get();
        return $query->result();
    }

我的观点

<table style="width: 100%">
            <tr>
                <th style="width: 5px">Serial No</th>
                <th style="width: 5px">Req. ID</th>
                <th style="width: 50px">Title</th> 
                <th style="width: 10px">Quantity</th>
                <th style="width: 10px">Unit</th>
                <th style="width: 20px">Managed By</th>
            </tr>
            <?php
            $slno = 0;
            if (!empty($user_data)) {
                foreach ($user_data as $user_fetcheach) {
                    $slno++;
                    ?>

                    <tr>

                        <td><?php echo$slno; ?></td>
                        <td><?php echo $user_fetcheach->rqm_id; ?></td>
                        <td><?php echo $user_fetcheach->rqmd_title; ?></td>
                        <td><?php echo $user_fetcheach->rqmd_quantity; ?></td>
                        <td><?php echo $user_fetcheach->name; ?></td>
                        <td><?php echo $user_fetcheach->emp_name; ?></td>


                    </tr>

                    <?php
                }
            }
            ?>
        </table>

0 个答案:

没有答案