显示数据库值

发布于 2024-12-12 02:48:46 字数 2524 浏览 0 评论 0原文

我正在尝试使用 Codeigniter 的表和分页库显示数据库中的数据。在我的模型中,除了其他列之外,我想从表“batch”中获取列“batchid”的信息,但在显示其他数据时不想在视图文件中显示它。

但由于我已在其中包含“batchid”(如下),

              $this->db->select('batchname, class, batchid, batchinstructor'); 

它在视图中显示“batchid”列的所有信息,这是我不想要的。我只想检索 batchid 的值以将其用于锚定“batchname”。

我已经尝试了很多但行不通。请您帮帮我好吗?

提前致谢

这是我的模型

//Function To Create All Student List
    function batch_list()
    {   
        $config['per_page'] = 15;
        $this->db->select('batchname, class,batchid, batchinstructor');
        $this->db->order_by("batchid", "desc"); 
        $rows = $this->db->get('batch',$config['per_page'],$this->uri->segment(3))->result_array();

        $sl = $this->uri->segment(3) + 1; // so that it begins from 1 not 0
        foreach ($rows as $count => $row)
            {
                array_unshift($rows[$count], $sl.'.');
                 $sl = $sl + 1;

             $rows[$count]['batchname'] = anchor('batch_list/get/'.$row['batchid'],$row['batchname']);
             $rows[$count]['Edit'] = anchor('update_student/update/'.$row['batchname'],img(base_url().'/support/images/icons/edit.png'));
             $rows[$count]['Delete'] = anchor('report/'.$row['batchname'],img(base_url().'/support/images/icons/cross.png'));


            }
        return $rows;
    }
//End of Function To Create All Student List 

这是我的控制器

   function index(){
            $this->load->helper('html');  
            $this->load->library('pagination');
            $this->load->library('table');
          $this->table->set_heading('Serial Number','Batch Name','Class','Batch Instructor','Edit','Delete');

            $config['base_url'] = base_url().'batchlist/index';
            $config['total_rows'] = $this->db->get('batch')->num_rows();
            $config['per_page'] = 15;
            $config['num_links'] = 5;
            $config['full_tag_open'] = '<div class="pagination" align="center">';
            $config['full_tag_close'] = '</div>';

            $this->pagination->initialize($config);
            $data['tab'] = "Batch List";                
            $this->load->model('mod_batchlist');
            $data['records']= $this->mod_batchlist->batch_list();
            $data['main_content']='view_batchlist';
            $this->load->view('includes/template',$data);

        }   

I am trying to display data from database using Codeigniter's table and pagination library. In my model, apart from other column I want to fetch information of column "batchid" from my table "batch" ,but don't want to show it in the view file when I am displaying the other data.

But since I have included the "batchid" in this-(in the following)

              $this->db->select('batchname, class, batchid, batchinstructor'); 

It is showing all the information of the column "batchid" in the view, which I don't want. I just want to retrieve the value of batchid to use it for anchoring "batchname".

I have tried a lot but it won't work. Would you please kindly help me?

Thanks in Advance

Here is my model

//Function To Create All Student List
    function batch_list()
    {   
        $config['per_page'] = 15;
        $this->db->select('batchname, class,batchid, batchinstructor');
        $this->db->order_by("batchid", "desc"); 
        $rows = $this->db->get('batch',$config['per_page'],$this->uri->segment(3))->result_array();

        $sl = $this->uri->segment(3) + 1; // so that it begins from 1 not 0
        foreach ($rows as $count => $row)
            {
                array_unshift($rows[$count], $sl.'.');
                 $sl = $sl + 1;

             $rows[$count]['batchname'] = anchor('batch_list/get/'.$row['batchid'],$row['batchname']);
             $rows[$count]['Edit'] = anchor('update_student/update/'.$row['batchname'],img(base_url().'/support/images/icons/edit.png'));
             $rows[$count]['Delete'] = anchor('report/'.$row['batchname'],img(base_url().'/support/images/icons/cross.png'));


            }
        return $rows;
    }
//End of Function To Create All Student List 

Here is my controller

   function index(){
            $this->load->helper('html');  
            $this->load->library('pagination');
            $this->load->library('table');
          $this->table->set_heading('Serial Number','Batch Name','Class','Batch Instructor','Edit','Delete');

            $config['base_url'] = base_url().'batchlist/index';
            $config['total_rows'] = $this->db->get('batch')->num_rows();
            $config['per_page'] = 15;
            $config['num_links'] = 5;
            $config['full_tag_open'] = '<div class="pagination" align="center">';
            $config['full_tag_close'] = '</div>';

            $this->pagination->initialize($config);
            $data['tab'] = "Batch List";                
            $this->load->model('mod_batchlist');
            $data['records']= $this->mod_batchlist->batch_list();
            $data['main_content']='view_batchlist';
            $this->load->view('includes/template',$data);

        }   

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

用心笑 2024-12-19 02:48:46

我不确定您在视图中做什么,但您可以通过循环数据集来手动添加行:

foreach ($records->result() as $r)
{
    $this->table->add_row($r->serial, 
                          $r->batchname, 
                          $r->class, 
                          $r->batchinstructor,
                          $r->edit,
                          $r->delete
                  );
}
echo $this->table->generate();

通过这种方式,您可以控制将哪些数据发送到表中。

I'm not sure what you're doing in your view, but you can add rows manually by looping through your dataset:

foreach ($records->result() as $r)
{
    $this->table->add_row($r->serial, 
                          $r->batchname, 
                          $r->class, 
                          $r->batchinstructor,
                          $r->edit,
                          $r->delete
                  );
}
echo $this->table->generate();

In this way, you control what data goes to your table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文