1
votes

This seems to be such an easy thing to do but I can't fine any information on how to do it. Can someone please tell me how to add the results of a query to an article in Joomla 2.5?

In an article this is what I am trying to accomplish.

Bob's favorite color is: <<SELECT favorite_color FROM COLORS WHERE name = 'Bob'>>

I have no idea how to do this.

2

2 Answers

1
votes

First thing is first, download and install the Sourcerer plugin which will allow you to add custom code to your articles.

One done, open your article and click the "Add Code" button below the textarea. Here you can add you custom code.

I'll write more or less the query you want using Joomla coding standards which most people seem to forget about:

$db = JFactory::getDbo();

$query = $db->getQuery(true);
$query->select($db->quoteName(array('favorite_color')))
      ->from($db->quoteName('colors'))
      ->where($db->quoteName('name') . ' = '. $db->quote('bob'));
$db->setQuery($query);
$rows = $db->loadObjectList();

foreach ($rows as $row) {
    echo $row->favorite_color;
}

Notes that if the colors tables belongs to a Joomla extensions, then use #__colors

Hope this helps

0
votes

You can make a content plugin. THe other thing is that you can make a module to show the data and then use loadposition to load the module.