⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

List of more than one table



sstekols
  • profile picture
  • Member

Posted 19 July 2015 - 03:39 AM

There is anyway to show the registers of more than one table or I have to develop with CodeIgniter?

Thank in advance.

 

 


Paul Savostin
  • profile picture
  • Member

Posted 19 July 2015 - 10:12 AM

Can you give some more explanation? Because I dont understand at all! What means develop Codeigniter? Now are you not develop with CI?


sstekols
  • profile picture
  • Member

Posted 19 July 2015 - 12:53 PM

Paul, thanks for your response.
When I referred to more than 1 table is:

 

SELECT a.field1, a. field2, b.field1, b.field2, c.field1, c.field3

FROM table_a a, table_b b, table_c c

WHERE a.field1 = b.field4

AND b.field5 = c.field1

 

I hope I have clarified my question.

Regards,

 

Sergio


Paul Savostin
  • profile picture
  • Member

Posted 19 July 2015 - 15:53 PM

1)You can use custom model where u select additional fields
2)You can use callbacks for fields from other table

But there is no default functionality in GC out of the box


sstekols
  • profile picture
  • Member

Posted 19 July 2015 - 18:42 PM

Paul,
 
   I am grateful for your answer.
   I try with the following code to implement the solution:

 

Controller: no_asignado.php
 
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class No_Asignado extends CI_Controller {
 
  function __construct()
  {
    parent::__construct();
 
    /* Cargamos la base de datos */
    $this->load->database();
 
    /* Añadimos el helper al controlador */
    $this->load->helper('url');
 
    /* Cargamos la libreria*/
    $this->load->library('grocery_CRUD');
 
  }
 
  function index()
  {
    try{
 
    $crud = new grocery_CRUD();
    $crud->set_table('table_em'); 
    $crud->set_subject('Prueba');
    $crud->set_language('spanish');
 
    $crud->unset_add();
    $crud->unset_edit();
    $crud->unset_delete();
 
    $crud->set_model('custom_query_model');
    $crud->basic_model->set_query_str('SELECT e.direccion,em.nombre FROM table_ed e,table_ed_em ee,table_em em WHERE e.id_ed=ee.id_ed AND ee.id_em=em.id_em');
 
    $output = $crud->render();
 
    $this->load->view('no_asignado', $output);
 
    }catch(Exception $e){
      show_error($e->getMessage().' --- '.$e->getTraceAsString());
    }
  }
}
 
Model: custom_query_model.php
 
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class Custom_query_model extends grocery_CRUD_model {
 
private  $query_str = ''; 
function __construct() {
parent::__construct();
}
 
function get_list() {
$query=$this->db->query($this->query_str);
 
$results_array=$query->result();
return $results_array;
}
 
public function set_query_str($query_str) {
$this->query_str = $query_str;
}
}

 

    but it gives me error.

    Thanks in advance.

    Regards,

 

           Sergio


Paul Savostin
  • profile picture
  • Member

Posted 19 July 2015 - 20:40 PM

/topic/264-join-tables/


sstekols
  • profile picture
  • Member

Posted 27 August 2015 - 02:33 AM

Paul,

 

      Thank you very much.

      Best regards,

 

              Sergio