我在ci中使用数组。每当我存储我只能得到最后的元素!其他元素都会被覆盖。
这是我的代码
$table="wp_term_taxonomy";
$data=array();
$this->db->where('taxonomy','Geographical');
$query = $this->db->get($table);
if ($query->num_rows() > 0)
{
foreach ($query->result() as $value) {
$terms_id=$value->term_id;
$table2="wp_terms";
$this->db->where('term_id',$terms_id);
$query2 = $this->db->get($table2);
if ($query2->num_rows() > 0)
{
foreach ($query2->result() as $value2) {
$data['name']=$value2->name;
$data['id']=$value2->term_id;
}
}
}
}
var_dump($data);
return $data;
}
我只获得$data
数组
答案 0 :(得分:4)
你是最重要的价值观。试试这样:
foreach ($query2->result() as $value2) {
$data[]=array('name' => $value2->name, 'id' => $value2->term_id);
}
答案 1 :(得分:2)
试试这个:
foreach ($query2->result() as $value2) {
$data[]['name']=$value2->name;
$data[]['id']=$value2->term_id;
}