gpt4 book ai didi

mysql - 我想要在单个模型函数中包含一组查询,并在 Codeigniter 中进行分页

转载 作者:行者123 更新时间:2023-11-29 21:35:37 24 4
gpt4 key购买 nike

     This is my model

不知道正确与否。我有一个带分页的 View 页面。我必须用新列显示计数字段。所以我必须在单个模型函数中编写查询数组。请帮忙。请告诉它如何正确调用 Controller

型号

public function fetch_data($limit, $start) {
$query1= $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');
$this->db->get();


$query2= $this->db->select('count(*)');
$this->db->from('jil_mrorfq');
$this->db->join('jil_requirements', 'jil_requirements.rqm_id=jil_mrorfq.rfq_requirementid', 'left');
$this->db->get();
return array(
'categories' => $query1,
'count' => $query2,
);
} public function fetch_data($limit, $start) {
$query1= $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');
$this->db->get();


$query2= $this->db->select('count(*)');
$this->db->from('jil_mrorfq');
$this->db->join('jil_requirements', 'jil_requirements.rqm_id=jil_mrorfq.rfq_requirementid', 'left');
$this->db->get();
return array(
'categories' => $query1,
'count' => $query2,
);
}

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;
$query= $this->requirement_model->
fetch_data($config["per_page"], $page);

$data['results'] = $query['categories'];
$data['count'] = $query['count'];
print_r($data['results']);
print_r( $data['count']);


$data["links"] = $this->pagination->create_links();


$this->load->view('moderator/managerequirement', $data);

$this->load->view('moderator/templates/footer');
}

查看

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Dashboard) -->
<section class="content-header">
<h1>
Requirement Management
<small></small>
</h1>
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
<li class="active">Requirements</li>
<li class="active">View All Requirements</li>
</ol>
</section>

<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">View all Requirements</h3> <div style="float:right"><?php echo $links; ?> </div>
</div><!-- /.box-header -->
<!-- form start -->

<div class="box-body">
<div class="row">
<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>
<div class="col-xs-6">

</div>
</div>




</diV>
</form>
</div><!-- /.box-body -->


</div>
</div>
</section>
<!-- /.content -->
</div><!-- /.content-wrapper -->

最佳答案

尝试这个编码

 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');
$get_query1 = $this->db->get();
$query1 = $get_query1->result();



$this->db->select('rfq_requirementid');
$this->db->from('jil_mrorfq');
$this->db->join('jil_requirements', 'jil_requirements.rqm_id=jil_mrorfq.rfq_requirementid', 'left');
$get_query2 = $this->db->get();
$field_count = $get_query2->num_rows();

return array(
'categories' => $query1,
'count' =>$field_count
);
}

关于mysql - 我想要在单个模型函数中包含一组查询,并在 Codeigniter 中进行分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34940454/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com