[英]Codeigniter & Datamapper: Retrive all the ID's from ID column and attach to array
I am having trouble collecting all the ids from the ID column. 我在从ID列收集所有ID时遇到问题。 What the code above does is getting only one ID, at least it goes to the array but I want to take all of them. 上面的代码所做的只是获得一个ID,至少它进入了数组,但我想全部使用。
$getArticlesId = new Article_model();
$getArticlesId->select('id');
$getArticlesId->get();
$anarray = $getArticlesId->to_array(array('id'));
That returns: SELECT articles
. 返回:SELECT articles
。 id
FROM ( articles
) id
FROM( articles
)
and Array ( [id] => 43 ) , but there must be 10 more 和Array([id] => 43),但必须再有10个
What I am doing wrong ? 我做错了什么?
to_array()
generates an array with your specified field(s). to_array()
使用您指定的字段生成一个数组。 all_to_array()
generates multiple arrays with your specified id field. all_to_array()
使用您指定的id字段生成多个数组。 $anarray[0]['id']
should be your first id. $anarray[0]['id']
应该是您的第一个ID。 Hope this is what you're looking for. 希望这是您想要的。
This should work: 这应该工作:
// RETURN ORM OBJECT
$getArticlesId = new Article_model();
$getArticlesId->select('id');
$getArticlesId->get_iterated();
$getArticlesId_Total = $getArticlesId->result_count();
// -------- EOF - RETURN ORM OBJECT
// GENERATE PHP ARRAY FROM OBJECT
if ($getArticlesId_Total > 1)
{
$anarray = $getArticlesId->all_to_array();
}
// -------- EOF - GENERATE PHP ARRAY FROM OBJECT
You may also want to try all_to_single_array() . 您可能还想尝试all_to_single_array() 。 http://datamapper.wanwizard.eu/pages/extensions/array.html http://datamapper.wanwizard.eu/pages/extensions/array.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.