Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 设置默认值codeigniter_Php_Codeigniter - Fatal编程技术网

Php 设置默认值codeigniter

Php 设置默认值codeigniter,php,codeigniter,Php,Codeigniter,我有此功能获取\u配置文件\u信息 function get_profile_info() { $this->db->where('username',$this->session->userdata('username')); $get_profile_info = $this->db->get('memberships'); if($get_profile_info->num_rows() == 1){ for

我有此功能获取\u配置文件\u信息

function get_profile_info()
{
    $this->db->where('username',$this->session->userdata('username'));
    $get_profile_info = $this->db->get('memberships');
    if($get_profile_info->num_rows() == 1){
        foreach ($get_profile_info->result() as $row)
    {
        echo $row->firstname;
        echo $row->lastname;
    }
        }   
}
问题是如何将结果:firstname和lastname放入输入表单default set_值:echo firstname.form_input'firstname2'

请尝试以下代码:

 foreach($get_profile_info->result() as $row)
    {
        $data = array(
              'name'        => 'firstname',
              'id'          => 'firstname',
              'value'       => $row->firstname,              
            );
        echo form_input($data);
       // do the same for lastname
    }

像这样设置视图文件的输入值

<input type="text" value="<?php echo $data['firstname']; ?>" />
您必须从控制器传递数据数组。

试试这个

鉴于


或者如何将查询结果放入表单集_值中
function get_profile_info()  
{
    $this->db->where('username',$this->session->userdata('username'));
    $get_profile_info = $this->db->get('memberships');
    if($get_profile_info->num_rows() == 1){
        return $get_profile_info->row();      
}
function your_controller
{
     $data['row'] = get_profile_infor()

     $this->load->view("yourview",$data)
}
<input type="text" name="firstname" value="<?php echo set_value('firstname',$row->firstname)?>" />
<input type="text" name="lastname" value="<?php echo set_value('lastname',$row->lastname)?>" />