I have two tables Table1(7 Cols) and Table2(5 Cols)......How to join both tables and display them in single table(12 Cols) using grocery crud?
⚠ 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. ⚠
Posted 03 April 2018 - 11:25 AM
I have two tables Table1(7 Cols) and Table2(5 Cols)......How to join both tables and display them in single table(12 Cols) using grocery crud?
Posted 03 April 2018 - 23:44 PM
you need to write custom model to get it worked around like that.
That is the easaiest way to get it resolved.
Posted 04 April 2018 - 06:11 AM
This is my Controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Main extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper('url');
/* ------------------ */
$this->load->library('grocery_CRUD');
}
public function index()
{
echo "<h1>Welcome to the world of Codeigniter</h1>";//Just an example to ensure that we get into the function
die();
}
function test()
{
$crud = new grocery_CRUD();
$crud->set_model('MainModel');
$crud->set_theme('datatables');
$crud->set_field_upload('Logo','assets/uploads/files');
$crud->set_field_upload('Document','assets/uploads/files');
$output = $crud->render();
$this->_example_output($output);
}
function _example_output($output = null)
{
$this->load->view('our_template.php',$output);
}
}
This is my Custom Model:
<?php
class MainModel extends Grocery_crud_model {
protected $primary_key = 'Id';
protected $table_name = 'pictures';
function __construct()
{
parent::__construct();
}
function joinTable($id = null, $order_by = null){
if(is_numeric($id)){
$this->db->where($this->primary_key,$id);
}
if(is_array($id)){
foreach($id as $key => $_value){
$this->db->where($key,$_value);
}
}
$this->db->select('pictures.Name, city.Name');
$this->db->from('pictures');
$this->db->join('city','pictures.Id=city.Id');
$result = $this->db->get($this->table_name);
return $result->result_array();
}
}
?>
Here i want to display Name Column from Pictures Table and Another Name Column from City Table using joins In GC
But for this code it is displaying the complete Pictures Table. Can u please figure out my problem