Reputation: 4596
for($i=0; $i < count($cameras_info); $i++){
$this->db->select('Image');
$this->db->from('cameras');
$this->db->where('id', $cameras_info[$i]->camera_id);
$cameras_info[$i]->Image = isset($this->db->get()->row()->Image) ? $this->db->get()->row()->Image : NULL;
}
When i trying to execute this code i receive this error:
Error Number: 1096
No tables used
SELECT *
Line Number: 167
How to solve this problem?
Upvotes: 0
Views: 1896
Reputation: 4250
The problem seems in this line:
$cameras_info[$i]->Image = isset($this->db->get()->row()->Image) ? $this->db->get()->row()->Image : NULL;
$this->db->get()
executes the query and reset values passed in active record class so when it called after question mark it does not get any values and raises the error. So replace this line with the following:
$result = $this->db->get()->row()->Image;
$cameras_info[$i]->Image = isset($result->row()->Image) ? $result->row()->Image : NULL;
Upvotes: 1
Reputation: 4527
Assuming you code is correct
I tried to restructure it as i see fit to your code
for($i=0; $i < count($cameras_info); $i++){
$this->db->select('Image');
$this->db->from('cameras');
$this->db->where('id', $cameras_info[$i]->camera_id);
$query = $this->db->get();
$cameras_info[$i]->Image = isset($query->row()->Image) ? $query->row()->Image : NULL;
}
Upvotes: 0