i have a manage page with pagination with field like Requirement Service,Posted By,Managed By,Quantity,Posted On,Status from the table requirement. i have to show a new filed count.that is the count of each requirement id in jil_mrorfq table. i done the portion of manage.but i dont konw how show the count,how it fetch together with this code.Anyone know the query,please help me to do this task. i correctly done the manage page with pagination.but the count of each requirement id have to show as next field in the table.i am totally confused how it fetch.how the query will write.anybody knows the answer,then please help me to complete this task.
MY 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'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$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');
}
MY Model
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;
}
View
<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>
Use below code
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;
}
Try this coding
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 $key=>$row) {
$data[$key] = $row;
$this->db->select('jil_mrorfq.rfq_requirementid');
$this->db->from('jil_mrorfq');
$this->db->join('jil_requirements', 'jil_requirements.rqm_id=jil_mrorfq.rfq_requirementid', 'left');
$this->db->group_by('jil_requirements.rqm_id');
$query2= $this->db->get();
$data[$key]['count'] =$query2->num_rows();
}
return $data;
}
return false;
}