Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Is it possible to prefix the table name to database query result
  • I have two tables that i'm joining that have a column name that is the same. Is there a way to prefix the table name in the select statement so that the results don't overwrite. Kind of like how ORM operates. For example I have a table names places with a column "name"
    I also have a table named users with a column "name" If I join these two tables the result set will only have the places.name in the result.
  • @bperin, Is this using Query-Builder? If it is then the documentation states that you can provide an array containing column => alias for the select() portion.
    $query = DB::select(array('column' => 'alias'));
    

    Not sure if you could provide
    array('places.name' => 'place_name', 'places.*', 'users.*')
    

    to override the exact column in question. (Completely untested, just an idea). Hope that helps.
  • Scott Horsley wrote on Friday 2nd of March 2012:
    @bperin, Is this using Query-Builder? If it is then the documentation states that you can provide an array containing column => alias for the select() portion.
    $query = DB::select(array('column' => 'alias'));
    

    Not sure if you could provide
    array('places.name' => 'place_name', 'places.*', 'users.*')
    

    to override the exact column in question. (Completely untested, just an idea). Hope that helps.

    Thanks for responding. Yeah I just used the arrays to alias each column i wanted, but your second example was what I was trying to accomplish but with no luck.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion