如何从数据库检索数据并使用Codeigniter将其显示在html表中 [英] How to retrieve data from the database and display it in a html table using Codeigniter

查看:151
本文介绍了如何从数据库检索数据并使用Codeigniter将其显示在html表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我检索数据库数据和如何查看它在html table.is的编码我给的是正确的,如果不是你可以说如何我必须给。



  class edit_content extends CI_Controller {

function edit_content()
{
parent :: __ construct
$ this-> load-> model('editcontent_model');
$ this-> load-> helper('url');
$ this-> load-> library('acl');
$ this-> data = $ this-> editcontent_model-> get_contents();
}
}

查看 >

 < table> 
< tr>
< th>内容< / th>
< / tr>

<?php foreach($ this-> data as $ r):?>
< tr>
< tr><?php echo $ r ['content']; ?>
< / tr>
<?php endforeach; ?>

< table>

模型

  class editcontent_model extends CI_Model {
var $ CI;

function editcontent_model(){
parent :: __ construct();
}

function get_contents(){
$ this-> db-> select('content');
$ this-> db-> from('content');
$ query = $ this-> db-> get();
return $ result = $ query-> result();
$ this-> load-> view('edit_content / edit_content',$ result);
}
}


解决方案

this:

 <?php 
#mycontroller
if(!defined('BASEPATH')) exit('No direct script access allowed');

class edit_content extends CI_Controller {

public function __construct(){
parent :: __ construct();
}

function edit_content()
{
$ data = array();
$ this-> load-> model('editcontent_model');
$ this-> load-> helper('url');
$ this-> load-> library('acl');
$ data ['result'] = $ this-> editcontent_model-> get_contents();
$ this-> load-> view('edit_content / edit_content',$ data);
}
}
?>
<! - myview - >
< table>
< tr>
< th>内容< / th>

< / tr>
<?php foreach($ result as $ r):?>
< tr><?php echo $ r-> content; ?>

< / tr>
<?php endforeach; ?>
< / table>
<?php
#mymodel
class editcontent_model extends CI_Model {
function get_contents(){
$ this-> db-> select );
$ this-> db-> from('content');
$ query = $ this-> db-> get();
return $ result = $ query-> result();
}
}


anyone please help me to retrieve the db data and how to view it in html table.is the coding i given is correct or not if not can you please say how i have to give. in order to view it in html table.

Controller

class edit_content extends CI_Controller {

    function edit_content()
    {
        parent::__construct();
        $this->load->model('editcontent_model');
        $this->load->helper('url');
        $this->load->library('acl');
        $this->data = $this->editcontent_model->get_contents();
    }
}

View

<table>
    <tr>
        <th>Content</th>
    </tr>

    <?php foreach($this->data  as $r): ?>
        <tr>
            <tr><?php echo $r['content']; ?>
        </tr>
    <?php endforeach; ?>

<table>

Model

class editcontent_model extends CI_Model {
    var $CI; 

    function editcontent_model(){
        parent::__construct();
    }

    function get_contents() {
        $this->db->select('content');
        $this->db->from('contents');
        $query = $this->db->get();
        return $result = $query->result();
        $this->load->view('edit_content/edit_content', $result);
    }
}

解决方案

Try this:

<?php
#mycontroller
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class edit_content extends CI_Controller    {

    public function __construct(){
        parent::__construct();
    }

    function edit_content()
    {
        $data   = array();
        $this->load->model('editcontent_model');
        $this->load->helper('url');
        $this->load->library('acl');
        $data['result'] = $this->editcontent_model->get_contents();
        $this->load->view('edit_content/edit_content', $data);
    }
}
?>
 <!-- myview -->
<table>
<tr>
<th>Content</th>

</tr>
<?php foreach($result  as $r): ?>
<tr><?php echo $r->content; ?>

    </tr>
<?php endforeach; ?>
</table>
<?php
#mymodel
class editcontent_model extends CI_Model{
    function get_contents() {
        $this->db->select('content');
        $this->db->from('contents');
        $query = $this->db->get();
        return $result = $query->result();
    }
}

这篇关于如何从数据库检索数据并使用Codeigniter将其显示在html表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆