gpt4 book ai didi

php - 连接 2 个表后如何在 Codeigniter View 中使用过滤器

转载 作者:行者123 更新时间:2023-11-29 16:22:11 25 4
gpt4 key购买 nike

我是 Codeigniter 的新手,并且坚持在我的 View 中显示过滤器的基本要求。我有一个包含成员详细信息的表(公司)和另一个名为“帐户”的表。我在那里存储了每个成员的付款详细信息。所以问题是,我必须将所有成员(member)和错过付款的成员(member)的详细信息提取到一个 View 中。我加入了 2 个表来将成员(member) ID (bh_id) 与帐户表相匹配,这样当帐户中不存在成员(member) ID 时,我就可以获得错过的成员(member)详细信息。我有两个输出,但我不想将其显示为 2 个 View ,而是想通过使用下拉过滤器将其显示在单个 View 中,例如 1) 所有成员(member) 2) 错过的成员(member)。

请参阅随附的屏幕截图:

表格公司:

enter image description here

表帐户:

enter image description here

建议的观点:

enter image description here

现在让我们看看我到目前为止所拥有的代码。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( Controller )

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>

请帮助我实现这一目标。感谢您的帮助:)

最佳答案

有两种方法可以做到这一点
首先使用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">

以及错过的成员(member)

<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 函数:
将其粘贴到 View 底部

<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>

关于php - 连接 2 个表后如何在 Codeigniter View 中使用过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54453855/

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