I followed the guide as in the documentation
My Controller
function progress()
{
$crud = new grocery_CRUD();
$crud->set_model('crud_model_1');
$crud->set_table('sales');
$output = $crud->render();
$this->_example_output($output);
}
Below is my model
First I tried as given in the documentation
class Crud_model_1 extends grocery_CRUD_Model {
function get_relation_n_n_unselected_array($field_info, $selected_values)
{
$selection_primary_key = $this->get_primary_key($field_info->selection_table);
if($field_info->name = '....')
{
// MY QUERY
$this->db->query("SELECT n1.* FROM sales n1 LEFT JOIN sales n2 ON (n1.leadid = n2.leadid AND n1.id < n2.id) WHERE n2.id IS NULL and n1 manager ='ben' order by id desc");
}
$this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}");
$results = $this->db->get($field_info->selection_table)->result();
$results_array = array();
foreach($results as $row)
{
if(!isset($selected_values[$row->{$field_info->primary_key_alias_to_selection_table}]))
$results_array[$row->{$field_info->primary_key_alias_to_selection_table}] = $row->{$field_info->title_field_selection_table};
}
return $results_array;
}
}
But all I get is all the details from the sales table. Unfortunately the query in the model doesn’t seem to be working.
And then I just tried the below model
function thelist()
{
$progress= $this->db->query(" SELECT n1.* FROM sales n1 LEFT JOIN sales n2 ON (n1.leadid = n2.leadid AND n1.id < n2.id) WHERE n2.id IS NULL and n1.manager ='ben' order by id desc");
$results_array=$progress->result()
return $results_array;
}
All I get is only the details from the complete sales table…not the results from the model.
Can someone please tell me how to get the set_model() working and what am I doing wrong?