[eluser]syncronos[/eluser]
THE PROBLEM:
The 2 tables I want to join have ambiguous columns (
id and
name are columns in both the events table and venues table
*see below). This is a problem because i need to output both the event name and venue name, but when I JOIN the table, one is over-riding the other. Additionally, when looking in the manual I didn't see an alias function in the database class.
OPTIONS:
Option 1.) Don't use Active Record and alias the columns in the SQL query. I don't prefer this option though; I want AR's escaping, cleanliness, et al--I didn't see how to create aliases with the database class, as I mentioned. I was looking for something like
$this->db->alias('table.column' => 'alias'), but to no avail. Does this function exist?
Option 2.) Prefix my database columns in the mysql database:
event_name,
venue_name, etc so that there are not any duplicates--seems like a hack though.
Ideas? Suggestions? A Solution?
My code is pasted below--thanks in advance,
~Syn
TABLE EXAMPLES:
Code:
events (id, name, venue_id, day, description, price)
venues (id, name, day, street, city, state, zip)
*Notice that both the events table and venues table have duplicate columns: id & name.
MODEL CODE:
Code:
function display_event()
{
$this->db->select('*');
$this->db->from('events');
$this->db->join('venues', 'venues.id = events.venue_id');
$query = $this->db->get();
return $query;
}
PRINT RECURSIVE
Code:
print_r($query->result());
Array
(
[0] => stdClass Object
(
[id] => 1
[venue_id] => 1
[name] => Venue Name
[day] => 2009-01-30 22:00:00
[description] => Lorem ipsum dolor sit amet
[price] => 11.11
[street] => 123 Magnolia Ave
[city] => Orlando
[state] => Florida
[zip] => 32801
)
)
*Notice that there is only 1 id and name column for venue, whereas I also need an id and name column for event.