2

I am working on a projecj with codeigniter, and it's my first time using GroceryCRUD, and I need to make that a patient can have any number of reports, I have this on my database.

enter image description here

Where idpatients is the foreign key.

I am using this on my controller

public function reports() 
{
    $crud=$this->grocery_crud;
    $crud->set_table('reports');
    $crud->set_subject('Reports'); 
    $crud->set_language('english');
    $crud->set_relation('idpatients','patients','Patient');
    $output=$crud->render();
    $this->load->view('admin_reports', $output);
}

And I get this error

enter image description here

Any help would be appreciated to fix it, How can I declare the relationship so when I add a new report I can choose the patient from a dropdownbox or something?

UPDATE

When I change db_debug for false I get this error

enter image description here

Ricardo Rios
  • 255
  • 7
  • 23

2 Answers2

1

Based on documentation:

void set_relation( string $field_name , string $related_table, string $related_title_field [, mixed $where [, string $order_by ] ] )

Set a relation 1-n database relation. This will automatically create a dropdown list to the fields and show the actual name of the field and not just a primary key to the list.

Which means, it will display the field from the table other then primary key (and you are trying to display field Patient which is not present in patients).

Solution for your issue - replace Patient with Name (or some other field which is present in patinets table):

$crud->set_relation('idpatients','patients','Name');
Ivan Jovović
  • 5,238
  • 3
  • 29
  • 57
0
$crud->set_relation('idpatients', 'patients', 'name');

This create a drowpdownList with the name of patients from your table patients

Your problem is "Patient", this column not exist on your table patients, for change the name on view use:

$crud->display_as('idpatients', 'Patient');

I'm sorry for my English