简体   繁体   English

如何在 Codeigniter 的关联数组中访问单个值

[英]How to get access single value in associative array of Codeigniter

This is my controller and model.这是我的 controller 和 model。

Please help me in view pages abc to display a specific column in the table field.请帮助我查看页面abc以在表格字段中显示特定列。

public function abc()
{
    $n=$this->uri->segment(3);
    $svc['id'] =$this->Admin_model->getallserv($n);
    $this->load->view('abc',$svc);
}

public function getallserv($n)
{
    $sql = "select * from services where id=$n";     
    $query = $this->db->query($sql);   
    return $query->result();
}
 - Update `$query->result()` to `$query->row_array()`  
 - Then result    will be like `array('column_name' =>
   'value','column_name' =>    'value'.........)`
 - assign to  `$svc` and in view you can access values like $svc->column_name


public function abc()
{
    $n=$this->uri->segment(3);
    $svc =$this->Admin_model->getallserv($n);
    $this->load->view('abc',$svc);
}

public function getallserv($n)
{
  $sql = "select * from services where id=$n";     
  $query = $this->db->query($sql); 
  return  $query->row_array();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM