Welcome Guest, Not a member yet? Register   Sign In
Database Question regarding Categories/Types
#1

[eluser]Jesse Schutt[/eluser]
Hey All, I've got a question on how to best work with a category/type table in my db. Let's see if I can explain this...

I have a table that contains event data such as:

EVENTS TABLE
event_id
event_name
event_type_code

I also have a table that stores the event types or categories.

EVENT_TYPE_CODE
event_type_code
event_type_name

What I am trying to accomplish is to be able to pull the list of available event type names in a dropdown list. I have an html table that lists all the rows from the EVENTS TABLE and I need to be able to identify which event is of what type. In other words, in my events table a row will have data such as "event_id = 1", "event_name = 'Family Retreat'", "event_type_code = 2". In the EVENT_TYPE_CODE table, there would be a corresponding row that says "event_type_code = 2" and "event_type_name = Family Events".

Is this making any sense? I obviously know that I need a model that will pull the events from the DB, but I'm confuse as to how to assign the particular event_type_code with the name of that event.

Please, ask me questions to clarify this!

Thanks
#2

[eluser]johnwbaxter[/eluser]
Well, you want to do a join don't you?

Like this:

$this->db->select('*');
$this->db->from('events_table');
$this->db->join('event_type_code', 'event_type_code.event_type_code = events_table.event_type_code');
$this->db->get()

Or have i missed something?
#3

[eluser]Jesse Schutt[/eluser]
Thanks a ton! This was the direction I needed :-)




Theme © iAndrew 2016 - Forum software by © MyBB