Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.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
Arrays CodeIgniter中的数组到字符串转换错误?_Arrays_Codeigniter_Foreach - Fatal编程技术网

Arrays CodeIgniter中的数组到字符串转换错误?

Arrays CodeIgniter中的数组到字符串转换错误?,arrays,codeigniter,foreach,Arrays,Codeigniter,Foreach,这是密码 我的控制器文件 public function view_resume($id) { $this->load->model('ORB_Model'); $data['get_masterData'] = $this->ORB_Model->get_masterData($id); } 我的模型文件: public function get_educationData($id) { return $this->db

这是密码

我的控制器文件

public function view_resume($id)
{
    $this->load->model('ORB_Model');

    $data['get_masterData'] = $this->ORB_Model->get_masterData($id);
}
我的模型文件:

public function get_educationData($id)
    {
        return $this->db->get_where('edu_tb',['edu_id'=>$id],2)->result_array();
    }
我的视图文件:

<?php
     print_r($get_educationData);
die;
// output array()
foreach ($get_educationData as $key){
?>
 value="<?php echo $key->['edu_name']; ?>"
 <?php
} 
?>

value=“”
现在,当我打印$get\u educationData时,它只会给出空数组()。 我的数据不是来自模型。
在我的视图文件中,没有显示任何内容。

您的控制器应如下所示:

public function get_educationData($id)
{
    if ( ! empty($id))
    {
        $query = $this->db->get_where('edu_tb', array('edu_id' => $id));
    }
    else
    {
        $query = $this->db->get('edu_tb');
    }

    if ($query->num_rows() > 0)
    {
        return $query->result_array();
    }
}
您必须在控制器中调用
get_educationData
方法,如下所示:

public function get_educationData($id)
{
    if ( ! empty($id))
    {
        $query = $this->db->get_where('edu_tb', array('edu_id' => $id));
    }
    else
    {
        $query = $this->db->get('edu_tb');
    }

    if ($query->num_rows() > 0)
    {
        return $query->result_array();
    }
}
您的模型应如下所示:

public function get_educationData($id)
{
    if ( ! empty($id))
    {
        $query = $this->db->get_where('edu_tb', array('edu_id' => $id));
    }
    else
    {
        $query = $this->db->get('edu_tb');
    }

    if ($query->num_rows() > 0)
    {
        return $query->result_array();
    }
}
你的观点应该是这样的:

public function get_educationData($id)
{
    if ( ! empty($id))
    {
        $query = $this->db->get_where('edu_tb', array('edu_id' => $id));
    }
    else
    {
        $query = $this->db->get('edu_tb');
    }

    if ($query->num_rows() > 0)
    {
        return $query->result_array();
    }
}
由于返回数据是数组形式的,所以使用数组代替对象表示法



显示如何在控制器中传递视图中的数据,以便打印($get\u masterData)而不是
打印($get\u educationData)打印(获取主数据);正在工作bcz i仅返回单行,但在get_educationData中,我希望在单个master_id中获得多个数据,这就是我使用foreachloop的原因。这就是为什么我要求您显示如何在controller pls show中传递视图中的数据,以便从中获得帮助。我在代码$data['get\u educationData']=$this->ORB\u Model->get\u educationData($id)中使用了它;视图与您发送的一样,但当我打印时($get_educationData)是仅打印数组(),如此确保您的
edu_tb
表中有相应
edu id
的数据,它有我多次插入测试的数据。我已更新了您的模型方法
get_educationData
请检查我更新的答案,希望这将有助于您打印($get_educationData)不显示任何内容,var_dump为o/p NULL,并且在运行时出错时foreach的参数无效