如何从mysql数据库中获取数据并使用codeigniter显示它以进行查看。

时间:2022-02-28 12:52:10

hey guys i have a table in database and i want to retrieve data from it and display to view . . i have tried many methods but none of these working . . pls help . . this is my controller code:

嘿家伙我在数据库中有一个表,我想从中检索数据并显示查看。 。我已经尝试了很多方法,但这些方法都没有。 。请帮助。 。这是我的控制器代码:

function getname()
{
    $this->load->model('user'); //load the user class
    $data['member'] = $this->user->ar_getwhere();
    $this->load->view('home_content_view', $data);
}

this is my model:

这是我的模特:

function ar_getwhere()
{
    $this->db->select('');
    $this->db->from('tbl_members');
    $this->db->where('member_name',$this->input->post('member_name'));
    $q = $this->db->get('');
    if($q->num_rows() > 0) 
    {
        $data = array();
        foreach($q->result() as $row) 
        {
            $data=$row;
        }
        return $data;
    }
}

2 个解决方案

#1


0  

I don't know what errors you're experiencing but anyway

我不知道你遇到了什么错误,但无论如何

You are receiving post data in the model? You should receive post data in the controller and send it to the model, and then, catch its response... And you should send the whole response as well.

您正在接收模型中的帖子数据?您应该在控制器中接收发布数据并将其发送到模型,然后捕获它的响应......您还应该发送整个响应。

function getname()
{
    $this->load->model('user'); //load the user class
    $data['member'] = $this->user->ar_getwhere($this->input->post('member_name'));
    $this->load->view('home_content_view', $data);
}


function ar_getwhere($memberName)
{
    $this->db->select('*');
    $this->db->from('tbl_members');
    $this->db->where('member_name',$memberName);
    $q = $this->db->get();
    if($q->num_rows() > 0) 
    {
        return $q->result();
    }
}

#2


0  

$q = $this->db->select('*')->from('tbl_members')
->where('member_name', $this->input->post('member_name'))
->get();

#1


0  

I don't know what errors you're experiencing but anyway

我不知道你遇到了什么错误,但无论如何

You are receiving post data in the model? You should receive post data in the controller and send it to the model, and then, catch its response... And you should send the whole response as well.

您正在接收模型中的帖子数据?您应该在控制器中接收发布数据并将其发送到模型,然后捕获它的响应......您还应该发送整个响应。

function getname()
{
    $this->load->model('user'); //load the user class
    $data['member'] = $this->user->ar_getwhere($this->input->post('member_name'));
    $this->load->view('home_content_view', $data);
}


function ar_getwhere($memberName)
{
    $this->db->select('*');
    $this->db->from('tbl_members');
    $this->db->where('member_name',$memberName);
    $q = $this->db->get();
    if($q->num_rows() > 0) 
    {
        return $q->result();
    }
}

#2


0  

$q = $this->db->select('*')->from('tbl_members')
->where('member_name', $this->input->post('member_name'))
->get();