我在Codeigniter较新,并且坚持在我的视图中显示过滤器的基本要求。我有一个包含成员详细信息的表(公司)和另一个名为“帐户”的表。我在那里存储了每个会员的付款明细。所以问题是,我必须将所有成员和错过付款的成员的详细信息收集到一个视图中。我已加入2个表以将成员ID(bh_id)与accounts表进行匹配,因此当帐户中不存在成员ID时,我可以获得丢失的成员详细信息。我都有两个输出,但是我不想将其显示为2个视图,而是希望使用下拉过滤器在单个视图中显示它,例如1)所有成员2)缺少成员。
请参阅所附的屏幕截图:
TABLE-companies:
TABLE帐户:
建议的视图:
现在,让我看看我到目前为止的代码。 Company_model.php
//Joining accounts to get missed member details in view
public function missed_members(){
$this->db->select("*");
$this->db->from("companies");
$this->db->join('accounts','accounts.bh_id = companies.bh_id','left');
$this->db->where('accounts.bh_id IS NULL');
$this->db->group_by('companies.bh_id');
$query = $this->db->get();
return $query->result();
}
Company.php(控制器)
public function index()
{
//All Companies
$data['company_data']= $this->Company_model->companies("companies");
// Missed Members
$data['missedmembers'] = $this->Company_model->missed_members();
$data['tab'] = 'tab1';
$data["page"] = "companies/company";
$this->load->view('dashboard', $data);
}
company.php(查看)
<section id="main-content">
<section class="wrapper">
<!-- page start-->
<div class="row">
<div class="col-lg-12">
<!--breadcrumbs start -->
<ul class="breadcrumb">
<li><a href="#"><i class="fa fa-building-o"></i> Accounts</a></li>
<li><a href="#">Member</a></li>
</ul>
<!--breadcrumbs end -->
<section class="panel">
<header class="panel-heading">
<a href="<?= base_url("company/add_company") ?>">
<button class="btn btn-primary btn-sm">
<i class="fa fa-plus-circle" aria-hidden="true"></i> Add New Member
</button>
</a>
<span class="tools pull-right">
<a href="javascript:;" class="fa fa-chevron-down"></a>
<a href="javascript:;" class="fa fa-times"></a>
</span>
<select>
<option>All Members</option>
<option>Missed Members</option>
</select>
</header>
<div class="panel-body">
<section>
<div class="adv-table">
<table class="display table table-bordered table-striped" id="dynamic-table">
<thead class="cf">
<tr>
<th>Book No</th>
<th>Name</th>
<th>Phone</th>
<th>Area</th>
<th>Staff Name</th>
<th>Book Details</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
foreach ($company_data as $value)
{
?>
<tr>
<td>
<?= $value->bh_m_id; ?>
</td>
<td>
<?= $value->bh_name; ?>
</td>
<td>
<?= $value->bh_phone; ?>
</td>
<td>
<?= $value->bh_area; ?>
</td>
<td>
<?= $value->ca_name; ?>
</td>
<td>
<a href="<?= base_url("accounts/index")?>/<?= $value->bh_id ?>">
<button class="btn btn-primary btn-xs">View Book</button>
</a>
</td>
<td>
<a href="<?= base_url("company/edit") ?>/<?= $value->bh_id ?>">
<button class="btn btn-success btn-xs"><span class="glyphicon glyphicon-edit"> </span> Edit</button>
</a>
</td>
<td>
<a href="<?= base_url("company/delete") ?>/<?= $value->bh_id ?>"
onclick="return confirm('Do You Really Want To Delete This Record')">
<button class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"> </span> Delete</button>
</a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</section>
</div>
</section>
</div>
</div>
</section>
</section>
请帮助我实现这一目标。感谢您的帮助:)
答案 0 :(得分:0)
有两种方法可以做到这一点
先用ajax
第二次捉迷藏
由于您是Codeigniter的新手,因此我将向您解释第二个
首先要做两个具有各自ID的表设计
使用
<table style='display:block;' class="table table-bordered table-striped" id="allMember_table">
respective code like you wrote in your view now
</table>
代替
<table class="display table table-bordered table-striped" id="dynamic-table">
以及错过的成员
<table style='display:none;' class="table table-bordered table-striped" id="missedMember_table">
respective code like you wrote in your view now
</table>
现在从此处粘贴下拉代码:
<select onchange="change_view(this.value);">
<option value="all">All Members</option>
<option value="missed">Missed Members</option>
</select>
现在从此处粘贴javascript函数:
将其粘贴到视图的底部
<script type="text/javascript">
function change_view(value){
if(value == "all"){
document.getElementById("allMember_table").style.display = "block";
document.getElementById("missedMember_table").style.display = "none";
}else{
document.getElementById("missedMember_table").style.display = "block";
document.getElementById("allMember_table").style.display = "none";
}
}
</script>