数组到字符串转换Codeignater_3
问题描述:
我在may模型中有一个问题,请帮助我!数组到字符串转换Codeignater_3
我在桶中有两个表,其中一个包含一个id,另一个表包含我们需要的所有列以及我们需要在视图中显示的信息。
型号:
function get_categories_id_in_tournament($id)
{
$this->ci->db->SELECT('weight_from AS w_from, weight_to AS w_to, gender AS gen, age_from AS a_from, age_to AS a_to');
$this->ci->db->FROM('categories');
$this->ci->db->JOIN('tournament_categories', 'category_id = id');
$this->ci->db->where('tournament_id', $id);
$query = $this->ci->db->get();
return $query->result_array();
}
控制器:
$data = array(
'get_categories' => $this->tournaments_model->get_categories_id_in_tournament($id),
);
检视:
foreach ($get_categories as $row2)
{
echo
$row2;
}
答
$数据=阵列(
'get_categories' => $this->tournaments_model->get_categories_id_in_tournament($id),
);
$ get_categories变量是一个多维数组,当你使用foreach循环时,那么$ row也会是一个数组而不是一个字符串,echo可以只打印字符串值可以t array that
s为什么它得到这个错误,所以请用户print_r改为循环内的回声。