I got the same error when I was working in a PHP project with the Code Igniter framework. In my model class there was a getprojectnames () method,
public function getprojectnames(){ $result['names']=array(); $this->db->select('name'); $this->db->from('project'); $this->db->where('status','Not Completed'); $query=$this->db->get(); return $query->result(); }
I wanted to call this function in the controller class and use it in the drop-down list in the view class.
So in my controller class
$this->data['projects'] =$this->testcase_model->getprojectnames(); $this->load->view("admin/_layout_main",$this->data);
In my class class,
<?php echo form_open('admin/check1'); ?> <div class="row" style=" margin-left: 10px; margin-top: 15px;"> <h5 class="box-title">Projects List : <? php echo form_dropdown('projects', $projects, 'id'); ?> </h5> <div> <input type="submit" style="width:200px;" class="btn btn-block btn-primary" value="Show Project TestCase Status" /></div> </div> <?php echo form_close();?>
When I ran this, I got an error saying that CI_DB_mysql_result could not convert to String.So I solved this problem by changing my code in the model class as shown below,
public function getprojectnames(){ $result['names']=array(); $this->db->select('name'); $this->db->from('project'); $this->db->where('status','Not Completed'); $query=$this->db->get(); foreach ($query->result() as $row) { array_push($result,$row->name); } return $result; }
Then my program worked fine.
Sithusena
source share