Welcome Guest, Not a member yet? Register   Sign In
How to output data from tables with same column names?
#1

[eluser]wdm*[/eluser]
This is my query:

Code:
$query = $this->db->query('
    SELECT archives.id, archives.signature, type_of_source.description, media_type.description, origin.description
    FROM archives, type_of_source, media_type, origin                                                            
    WHERE archives.type_of_source_id = type_of_source.id                                                          
    AND type_of_source.media_type_id = media_type.id                                                              
    AND archives.origin_id = origin.id                                                                            
    ORDER BY archives.id ASC
');

But how to output the result? This works, but only gets the last description (origin.description):

Code:
foreach ($query->result_array() as $row)
{
    echo $row['description'];
}

This doesn't work:

Code:
foreach ($query->result_array() as $row)
{
    echo $row['type_of_source.description'];
}

Or should I rename the columns (e.g. type_of_source_description)?
#2

[eluser]xwero[/eluser]
the easiest solution is to use aliases.
#3

[eluser]GSV Sleeper Service[/eluser]
as the man with the unpronounceable name said, use aliases.
Code:
SELECT
archives.id, archives.signature,
type_of_source.description as src_description,
media_type.description as media_description,
origin.description as orig_description ...
#4

[eluser]sexy22[/eluser]
up,me too!




Theme © iAndrew 2016 - Forum software by © MyBB