⚠ 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

Table relationships?



mztriz
  • profile picture
  • Member

Posted 23 April 2012 - 14:36 PM

I have two tables that I'm displaying with the GroceryCrud library in Codeigniter.

Ex.


function tblFitnessClasses()

{

$this->config->set_item('url_suffix', '');

$crud = new grocery_CRUD();



$crud->set_table('tblFitnessClasses');

$crud->columns('id','uid', 'title','description','location');

$crud->display_as('title','Event')

->display_as('id','ID')

->display_as('uid','UID')

->display_as('description','Description')

->display_as('location','Location');

$crud->required_fields('title','location');

$crud->set_subject('Event');



$output = $crud->render();

$this->_example_output($output);

}



function tblFitnessClassDateTimes()

{

$this->config->set_item('url_suffix', '');

$crud = new grocery_CRUD();



$crud->set_table('tblFitnessClassDateTimes');

$crud->columns('id','owner_uid','startDate','endDate','startTime', 'endTime', 'days', 'recurrance');

$crud->display_as('startDate','Start Date')

->display_as('endDate','End Date')

->display_as('id','ID')

->display_as('owner_uid','UID')

->display_as('startTime','Start Time')

->display_as('endTime','End Time');

$crud->set_subject('Date');



$output = $crud->render();



$this->_example_output($output);


However, what I would like to do is display the first table and then when you click edit display the edits for the first table and the second [color=#000000][font=Arial,](joined by uid and owner_uid).[/font][/color]

With the tblFitnessClassDateTimes(time/date info), information from these tables should only be shown for the specific event that the dates are tied to; when a user selects an event to edit (from tblFitnessClasses) , the associated date info is displayed and can be edited. Is this possible?

[color=#000000][font=Arial,]If not is it possible to join these two tables so that I can see and edit all of the data?[/font][/color]

[color=#000000]The two tables look like this:[/color]



CREATE TABLE `tblFacilityHrs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` varchar(45) DEFAULT NULL,
`title` varchar(100) DEFAULT NULL,
`description` text,
PRIMARY KEY (`id`),
KEY `key_uid` (`uid`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1$$

CREATE TABLE `tblFacilityHrsDateTimes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`owner_uid` varchar(45) DEFAULT NULL,
`startDate` date DEFAULT NULL,
`endDate` date DEFAULT NULL,
`startTime` time DEFAULT NULL,
`endTime` time DEFAULT NULL,
`days` int(2),
`recurrence` int(1) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `fk_fh_owneruid` (`owner_uid`),
CONSTRAINT `fk_fh_owneruid` FOREIGN KEY (`owner_uid`) REFERENCES `tblFacilityHrs` (`uid`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=latin1$$


[color=#282828][font=helvetica, arial, sans-serif]id uid title description location[/font][/color]
[color=#800000][font=helvetica, arial, sans-serif]1[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]8ada0ceabd40d509c3fb38f2822a97de11bc6628[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Swim[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Lessons[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Parent[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#00008B][font=helvetica, arial, sans-serif]and[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Child[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Classes[/font][/color][color=#282828][font=helvetica, arial, sans-serif] CRC[/font][/color]
[color=#800000][font=helvetica, arial, sans-serif]2[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]543a6ed0005ff6a0a7fc99cc2f9715d86804ecb0[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Swim[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Lessons[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Level[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]1[/font][/color][color=#282828][font=helvetica, arial, sans-serif], [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Session[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]1[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color]
[color=#800000][font=helvetica, arial, sans-serif]3[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]7d219b64be6dc706135bdad3e7c2f0d56cb7f353[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Swim[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Lessons[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Level[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]2[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color]
[color=#800000][font=helvetica, arial, sans-serif]4[/font][/color][color=#282828][font=helvetica, arial, sans-serif] f7c91e2f1daa9c696c22f5aa5736c167d1ba9f94 [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Swim[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Lessons[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Level[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]3[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color]
[color=#800000][font=helvetica, arial, sans-serif]5[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]262f06fb75645248162aa983f610ec7959a2011b[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Swim[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Lessons[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Level[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]4[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color]
[color=#800000][font=helvetica, arial, sans-serif]6[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]51f9f552ffc5fa4bc8b4e7f914fb22b3b0920c2e[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Bike[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]275[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Participate[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#00008B][font=helvetica, arial, sans-serif]in[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#00008B][font=helvetica, arial, sans-serif]this[/font][/color][color=#282828][font=helvetica, arial, sans-serif] program [/font][/color][color=#00008B][font=helvetica, arial, sans-serif]and[/font][/color][color=#282828][font=helvetica, arial, sans-serif] take [/font][/color][color=#800000][font=helvetica, arial, sans-serif]4[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Fitness[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Cycling[/font][/color][color=#282828][font=helvetica, arial, sans-serif] classes [/font][/color][color=#00008B][font=helvetica, arial, sans-serif]and[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#00008B][font=helvetica, arial, sans-serif]get[/font][/color][color=#282828][font=helvetica, arial, sans-serif] a FREE[/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Waterbottle[/font][/color][color=#282828][font=helvetica, arial, sans-serif]! [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Participants[/font][/color][color=#282828][font=helvetica, arial, sans-serif] can only [/font][/color][color=#00008B][font=helvetica, arial, sans-serif]register[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]1[/font][/color][color=#282828][font=helvetica, arial, sans-serif] time. [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]This[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#00008B][font=helvetica, arial, sans-serif]is[/font][/color][color=#282828][font=helvetica, arial, sans-serif] a FREE program! [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Sign[/font][/color][color=#282828][font=helvetica, arial, sans-serif] up [/font][/color][color=#00008B][font=helvetica, arial, sans-serif]in[/font][/color][color=#282828][font=helvetica, arial, sans-serif] the [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Multipurpose[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Room[/font][/color][color=#282828][font=helvetica, arial, sans-serif].[/font][/color]
[color=#800000][font=helvetica, arial, sans-serif]7[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]0cca3515ec8ee990c863e474fee634ae94d382c2[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Passport[/font][/color][color=#282828][font=helvetica, arial, sans-serif] to [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Fitness[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Take[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Norse[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Fitness[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Classes[/font][/color][color=#282828][font=helvetica, arial, sans-serif], [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Get[/font][/color][color=#282828][font=helvetica, arial, sans-serif] your [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Passport[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Stamped[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#00008B][font=helvetica, arial, sans-serif]and[/font][/color][color=#282828][font=helvetica, arial, sans-serif] win a[/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Free[/font][/color][color=#282828][font=helvetica, arial, sans-serif] T-shirt! [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Take[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]8[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Fitness[/font][/color][color=#282828][font=helvetica, arial, sans-serif] classes between [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]April[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]10[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#00008B][font=helvetica, arial, sans-serif]and[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]May[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]1[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#00008B][font=helvetica, arial, sans-serif]and[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#00008B][font=helvetica, arial, sans-serif]get[/font][/color][color=#282828][font=helvetica, arial, sans-serif] a [/font][/color][color=#2B91AF][font=helvetica, arial, sans-serif]Free[/font][/color][color=#282828][font=helvetica, arial, sans-serif] T-shirt.[/font][/color]

[color=#282828][font=helvetica, arial, sans-serif]id owner_uid startDate endDate startTime endTime days recurrance[/font][/color]
[color=#800000][font=helvetica, arial, sans-serif]1[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]8ada0ceabd40d509c3fb38f2822a97de11bc6628[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]4[/font][/color][color=#282828][font=helvetica, arial, sans-serif]/[/font][/color][color=#800000][font=helvetica, arial, sans-serif]13[/font][/color][color=#282828][font=helvetica, arial, sans-serif]/[/font][/color][color=#800000][font=helvetica, arial, sans-serif]2012[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]4[/font][/color][color=#282828][font=helvetica, arial, sans-serif]/[/font][/color][color=#800000][font=helvetica, arial, sans-serif]13[/font][/color][color=#282828][font=helvetica, arial, sans-serif]/[/font][/color][color=#800000][font=helvetica, arial, sans-serif]2012[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]0[/font][/color][color=#282828][font=helvetica, arial, sans-serif]:[/font][/color][color=#800000][font=helvetica, arial, sans-serif]00[/font][/color][color=#282828][font=helvetica, arial, sans-serif]:[/font][/color][color=#800000][font=helvetica, arial, sans-serif]00[/font][/color][color=#282828][font=helvetica, arial, sans-serif] NULL NULL [/font][/color][color=#00008B][font=helvetica, arial, sans-serif]None[/font][/color]
[color=#800000][font=helvetica, arial, sans-serif]2[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]543a6ed0005ff6a0a7fc99cc2f9715d86804ecb0[/font][/color][color=#282828][font=helvetica, arial, sans-serif] NULL NULL [/font][/color][color=#800000][font=helvetica, arial, sans-serif]12[/font][/color][color=#282828][font=helvetica, arial, sans-serif]:[/font][/color][color=#800000][font=helvetica, arial, sans-serif]30[/font][/color][color=#282828][font=helvetica, arial, sans-serif]:[/font][/color][color=#800000][font=helvetica, arial, sans-serif]00[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]2[/font][/color][color=#282828][font=helvetica, arial, sans-serif]:[/font][/color][color=#800000][font=helvetica, arial, sans-serif]00[/font][/color][color=#282828][font=helvetica, arial, sans-serif]:[/font][/color][color=#800000][font=helvetica, arial, sans-serif]00[/font][/color][font=helvetica, arial, sans-serif] [color="#2b91af"]2[/color][/font]
[color=#800000][font=helvetica, arial, sans-serif]3[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]7d219b64be6dc706135bdad3e7c2f0d56cb7f353[/font][/color][color=#282828][font=helvetica, arial, sans-serif] NULL NULL NULL NULL NULL NULL[/font][/color]
[color=#800000][font=helvetica, arial, sans-serif]4[/font][/color][color=#282828][font=helvetica, arial, sans-serif] f7c91e2f1daa9c696c22f5aa5736c167d1ba9f94 NULL NULL NULL NULL NULL NULL[/font][/color]
[color=#800000][font=helvetica, arial, sans-serif]5[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]262f06fb75645248162aa983f610ec7959a2011b[/font][/color][color=#282828][font=helvetica, arial, sans-serif] NULL NULL NULL NULL NULL NULL[/font][/color]
[color=#800000][font=helvetica, arial, sans-serif]6[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]51f9f552ffc5fa4bc8b4e7f914fb22b3b0920c2e[/font][/color][color=#282828][font=helvetica, arial, sans-serif] NULL NULL NULL NULL NULL NULL[/font][/color]
[color=#800000][font=helvetica, arial, sans-serif]7[/font][/color][color=#282828][font=helvetica, arial, sans-serif] [/font][/color][color=#800000][font=helvetica, arial, sans-serif]0cca3515ec8ee990c863e474fee634ae94d382c2[/font][/color][color=#282828][font=helvetica, arial, sans-serif] NULL NULL NULL NULL NULL NULL [/font][/color]

mztriz
  • profile picture
  • Member

Posted 25 April 2012 - 14:26 PM

Can this be done with a custom model?
Or with some kind of php hackaround that in the edit view calls another table with a matching uid and appends it to the current one?

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 25 April 2012 - 18:39 PM

You can always use the set_model method: http://www.grocerycrud.com/documentation/options_functions/set_model

mztriz
  • profile picture
  • Member

Posted 02 May 2012 - 16:21 PM

Thanks web-johnny. I appreciate all your help!

Raboo
  • profile picture
  • Member

Posted 30 May 2012 - 14:10 PM

mztriz, did you succeed with your problem?
I'm guessing that this is same as http://stackoverflow.com/questions/10450671/table-join-in-codeigniter-with-active-record-and-grocerycrud/10452304

I have a similar problem.
I want to display columns from multiple tables, that is simple, and aswell I want to display several columns from the joined tables, that also works. But I stuck at displaying the "multiple" joined columns in one column.
I want to display it like you want it. But when I edit I only want to edit the foregin key, not both tables.

TABLE1:
ID | NAME | COLUMN3 | COLUMN4 | FOREGIN_KEY_TABLE2
TABLE2:
ID | NAME | COLUM3 | COLUMN4

I want it displayed as:

NAME | COLUM3 | COLUMN4 | NAME.TABLE2 | COLUMN3.TABLE2 | COLUMN4.TABLE2

When editing I want to edit these fields:
NAME | COLUMN3 | COLUMN4 | FOREGIN_KEY_TABLE2


Is there a way to do this?

Raboo
  • profile picture
  • Member

Posted 30 May 2012 - 14:15 PM

I'm guessing this post is also related /topic/352-how-to-create-view-for-a-field-from-all-tables-it-is-related-to/.