php - 隐藏 CodeIgniter 中 $this->table->generate() 中生成的表列

标签 php mysql codeigniter

使用 codeigniter 一段时间了。

我正在从数据库生成数据,并使用 $this->table->generate(records); 组织表中的 View 数据

它会生成应该的内容,但是如果我想隐藏在查询中选择的 id 该怎么办?因为您在 $this->db->select(); 中选择的任何内容也会显示在表格中。

如何隐藏id或防止其显示在 View 中的表中?

提前致谢。

我的模型是:

function clist($search) {
        $config["per_page"] = 10;
        $where = "fn LIKE '%%".$search."%%' OR mn LIKE '%%".$search."%%' OR ln LIKE '%%".$search."%%' OR suffix LIKE '%%".$search."%%' OR address_common LIKE '%%".$search."%%' OR address_brgy LIKE '%%".$search."%%' OR address_city_prov LIKE '%%".$search."%%' OR con_num LIKE '%%".$search."%%' OR date(date_created) LIKE '%%".$search."%%'";

        $this->db->select('id, CONCAT(fn," ",mn," ",ln," ",suffix) AS name,CONCAT(address_common,", ",address_brgy,", ",address_city_prov) AS address,con_num', FALSE);
        $this->db->select("DATE_FORMAT(date_created, '%M %d, %Y - %T') AS date_created", FALSE);

        if (!empty($search)) {
            $this->db->where($where);
        }
        $this->db->order_by('id', 'ASC');
        $rows = $this->db->get('tbl_cust_info', $config['per_page'], $this->uri->segment(3))->result_array();

        $index = $this->uri->segment(3) + 1;

        foreach ($rows as $count => $row) {
            array_unshift($rows[$count], $index.'.');
            $index = $index + 1;

            $rows[$count]['name'] = anchor(base_url().'raffle/clist_details/?i='.$row['id'],$row['name']);
        } return $rows;
    }

我的 Controller 是:

public function clist() {
        $data["title"] = "Customers' List";

        $this->load->library('table');

        $data["records"] = $this->raffle_model->clist($search);

        $data['thead'] = $this->table->set_heading('#','Name<br /><small>(First Name Middle Name Last Name Suffix )</small>','Address <br /><small>(House #, Bldg. #, Compound, Street, Avenue etc., Barangay, City / Province)</small>','Contact No<br />&nbsp','Date Created<br />&nbsp');
        $data['ttamplate'] =  $this->table->set_template(
            array(
                    'table_open' => 
                        '
                            <div class="table-responsive">
                                <table class="table table-hover table-bordered table-striped table-condensed">
                                    <caption>
                                        <h3><strong>
                                            Customers
                                        </strong></h3>
                                        <small>Below are the list of customers.</small>
                                    </caption>
                        '
                ));

        $data['pagelinks'] = $this->pagination->create_links();

        $this->load->view("templates/header", $data);
        $this->load->view("templates/nav", $data);
        $this->load->view("pages/cust_list", $data);
        $this->load->view("templates/footer", $data);
    }

我的观点是:

<div class="row">
    <?php
        if(empty($records)){
        echo '<br /><br /><br /><div class="alert alert-danger" role="alert" style="text-align: center;"><strong>< < < No Customer found. > > ></strong></div>';
      }else{
          $thead;
          $ttemplate;
          echo $this->table->generate($records);
        }
      ?>
  </div>

最佳答案

假设您的所有数据都位于 $records 数组中,就像这样

$this->table->generate(array) // all the array columns will be strucured as table cells.
$records = [
    array("name"=>'sid',age=>21), 
    array("name"=>'sid',age=>21), 
    array("name"=>'sid',age=>21), 
];

您不想显示年龄列。你可以像这样创建新的数组

  $displayableRecords = array();
  foreach($records as $record)
    $displayableRecords = $record['name'];

并传递新数组来生成表。

关于php - 隐藏 CodeIgniter 中 $this->table->generate() 中生成的表列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39402924/

相关文章:

codeigniter - Codeigniter 事件记录中的子查询

php - 在 iPad 上运行原生 PHP 网站

php - 我应该在哪里看到 FirePHP 输出?

php - 下拉框内的列表项

php - 解析sql响应数组

c# - MySQL 查询返回参数列名

php - 如何在codeigniter中正确设置flash_message?

php - CodeIgniter 中有类似 $this->db->matched_rows() 的东西吗?

php - 在单个查询中将结果作为单个数组获取

php - 合并两个复杂查询