我有一个这样的查询:
function getnames(){
$sql = "select * from names where status = '1'";
$query = $this->db->query($sql);
if($query->num_rows()>0){
return $query->result();
}
else{
return null;
}
}
这个函数已经加载在new_model.php中。我正在使用CodeIgniter。
然后在控制器中,我使用返回查询结果的函数。我已经在控制器中设置了这个:
function getnames(){
return $this->new_model->getnames();
}
我想做的是,而不是使用foreach()循环来获取数组结果,我想使用其他东西,让我使用索引号。我该怎么做呢?请帮助。谢谢!
$index是您要查找的数字。
$name是$names[$index]
使用foreach ($names as $index => $name)
如何?