⚠ 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

Pulling data from relation table without unique key and displaying results in dropdown box in the base table



FoxfireTX

FoxfireTX
  • profile picture
  • Member

Posted 17 March 2018 - 15:06 PM

Hello:  First, thanks to everyone who takes the time to help out with this forum.  I love the GC display and functionality.  I am new to GC and CI but have managed to get them working individually with full functionality for 5 tables.  But I now need to pull data from one table into another and cannot get where I need to be.
 
Base table = 'file' with primary key 'ID'.  ID is the common element between the two tables.
 
Relation table ="history" with ID listed zero to multiple times with various dates in the 'date' field, whenever there is a new history another line gets added under that ID so there is no way to set a primary key for ID.
 

I need to pull that history table 'date' field data into my base table under history with a dropdown box listing all dates the ID is listed in the relation table.

 

public function file()
    {
$crud = new grocery_CRUD();
         
$crud->set_theme('bootstrap-v4');
$crud->set_table('file');
$crud->set_relation('ID', 'history', 'date');     
$crud->fields('ID', 'lastname', 'firstname', 'middlename', 'phone', 'street', 'address2', 'city', 'zip', 'history', 'birthdate', 'registrationdate',' gender');
$crud->columns('ID', 'lastname', 'firstname', 'phone', 'city'', 'history');
$crud->set_subject('Customer File');
$crud->display_as('date', 'History')

 

$output = $crud->render();
            $this->_grocery_crud_output($output);
   }
        function _grocery_crud_output($output = null)
            {
            $this->load->view('campaign.php',(array)$output);   
        }
     }

 

The first thing that happens is the data in the ID column disappeared in my base table "file", the History field did not populate and I now get an sql error message when I try to view the full entry.

 

I suspect this is very straight forward for someone who knows how to set relation tables and data, but I just cannot figure out how to get this to work.  I have read and reread the info on relations but it seems to rely on the primary key in the relation table which I cannot set with with mine because in the relation table the ID may well be listed multiple times.

 

Thanks so much for any help!

 

Since I posted this, I got the 'ID" in the History table set as foreign key thinking this might help, as well as the relation between the two tables in myphpadmin.  But I am still getting the same result, it is not populating the 'file' table with the 'date' info from the History table.