Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 2.01 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Getting results form a query to insert in other using active records
  2. $this->db->select('artworks.*, users.id as owner, users.name as user_name');
  3. $this->db->from('artworks');
  4. $this->db->join('users', 'users.id = artworks.user_id');
  5.  
  6. $category = $this->get_child_categories($this->get_categories(), $matches[1]);
  7. $this->db->where_in('artworks.category', $this->category['child']);
  8.  
  9. $this->db->group_by('artworks.id');
  10. $query = $this->db->get();
  11. return $query->result_array();
  12.        
  13. $this->db->select('*');
  14. $this->db->order_by('parent', 'asc');
  15. $this->db->order_by('name', 'asc');
  16. $query = $this->db->get('categories');
  17. return $query->result_array();
  18.        
  19. function get_child_categories($categories, $parent){
  20.     foreach($categories as $category){
  21.         if($category['parent'] == $parent){
  22.             array_push($this->category['childs'], $category['id']);
  23.             $this->get_child_categories($categories, $category['id']);
  24.         }
  25.     }
  26. }
  27.        
  28. Error Number: 1064
  29.  
  30. 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
  31.  
  32. 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
  33.  
  34. Filename: D:ServerhtdocsgallerysystemdatabaseDB_driver.php
  35.  
  36. Line Number: 330
  37.        
  38. $category = $this->get_child_categories($this->get_categories(), $matches[1]);
  39. # the first query gets executed here, your data context is cleaned up
  40.  
  41. $this->db->select('artworks.*, users.id as owner, users.name as user_name');
  42. $this->db->from('artworks');
  43. $this->db->join('users', 'users.id = artworks.user_id');
  44. $this->db->where_in('artworks.category', $this->category['child']);
  45. $this->db->group_by('artworks.id');
  46. $query = $this->db->get();
  47. # your second query gets executed here
  48. return $query->result_array();