1

I have this query:

$query
    ->select(array('a.id', 'a.alias', 'b.category_id', 'b.item_id', 'c.id', 'c.name', 'c.alias'))
    ->from($db->quoteName('#__zoo_category', 'a'))
    ->join('INNER', $db->quoteName('#__zoo_category_item', 'b') . ' ON (' . $db->quoteName('a.id') . ' = ' . $db->quoteName('b.category_id') . ')')
    ->join('INNER', $db->quoteName('#__zoo_item', 'c') . ' ON (' . $db->quoteName('b.item_id') . ' = ' . $db->quoteName('c.id') . ')')
    ->where($db->quoteName('a.alias') . ' = \'chubut\'');

As you can see, I'm recovering 2 alias: a.alias and c.alias. I need the browser displays 2 alias.

If I make a echo to $value->alias, the browser prints the c.alias, not the a.alias. Where is a.alias? How do I get it?

$db->setQuery($query);
$resultado = $db->loadObjectList();

foreach ($resultado as $key => $value) {
    echo "alias: $value->alias";
}
  • Have you tried using "AS" keyword? Like: ... c.alias AS alias2 ... – Krossfire Jul 16 '16 at 0:16
3

You can use AS keyword.

Try this:

$query
    ->select('a.id, a.alias AS cat_alias, b.category_id, b.item_id, c.id, c.name, c.alias AS item_alias')

    ...
    ...

;

Then

foreach ($resultado as $key => $value) {
    echo "alias: $value->cat_alias";
}

Note: Using AS keyword is not mandatory, so you can omit it. For example:

$query->select('a.id, a.alias cat_alias, c.alias item_alias');
| improve this answer | |
  • The idea is to put an alias to an alias! Wow great! It worked perfectly. Thank you very much! – George Berkeley Jul 17 '16 at 1:07
  • You're welcome :) ! Yes, for your problem, you must use alias of alias! – Farahmand Jul 17 '16 at 6:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.