- Getting results form a query to insert in other using active records
- $this->db->select('artworks.*, users.id as owner, users.name as user_name');
- $this->db->from('artworks');
- $this->db->join('users', 'users.id = artworks.user_id');
- $category = $this->get_child_categories($this->get_categories(), $matches[1]);
- $this->db->where_in('artworks.category', $this->category['child']);
- $this->db->group_by('artworks.id');
- $query = $this->db->get();
- return $query->result_array();
- $this->db->select('*');
- $this->db->order_by('parent', 'asc');
- $this->db->order_by('name', 'asc');
- $query = $this->db->get('categories');
- return $query->result_array();
- function get_child_categories($categories, $parent){
- foreach($categories as $category){
- if($category['parent'] == $parent){
- array_push($this->category['childs'], $category['id']);
- $this->get_child_categories($categories, $category['id']);
- }
- }
- }
- Error Number: 1064
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM (`artworks`, `categories`) JOIN `users` ON `users`.`id` = `artworks`.`use' at line 1
- SELECT `artworks`.*, `users`.`id` as user_id, `users`.`name` as user_name, * FROM (`artworks`, `categories`) JOIN `users` ON `users`.`id` = `artworks`.`user_id` WHERE `artworks`.`rating` IN ('g', 'm', 'a') ORDER BY `artworks`.`id` desc, `parent` asc, `name` asc
- Filename: D:ServerhtdocsgallerysystemdatabaseDB_driver.php
- Line Number: 330
- $category = $this->get_child_categories($this->get_categories(), $matches[1]);
- # the first query gets executed here, your data context is cleaned up
- $this->db->select('artworks.*, users.id as owner, users.name as user_name');
- $this->db->from('artworks');
- $this->db->join('users', 'users.id = artworks.user_id');
- $this->db->where_in('artworks.category', $this->category['child']);
- $this->db->group_by('artworks.id');
- $query = $this->db->get();
- # your second query gets executed here
- return $query->result_array();