Page 1 of 1

PHP in Joomla Problems

Posted: Fri Feb 29, 2008 8:53 pm
by Plaidfox
I could really use some help. I haven't really worked with PHP for about a year, and I'm still learning joomla. I have joomla 1.5 and I installed the IncludePHP plug-in. What I'm trying to do is pull information from my database onto an article. My code so far is:

{php} defined('_JEXEC') or die('Restricted access');

$db = &JFactory::getDBO();
$num = 1;
$db->setQuery( 'SELECT title FROM #__recipe WHERE id = 1' );
$row = $db->loadResult();
echo $row;
echo "<br />";

$db->setQuery( 'SELECT ingredients FROM #__recipe WHERE id = 1' );
$row = $db->loadResult();
echo $row;
echo "<br />";

$db->setQuery( 'SELECT directions FROM #__recipe WHERE id = 1' );
$row = $db->loadResult();
echo $row;
echo "<br />";

{/php}

I got the information on how to pull individual information from the database through the tutorial:
http://dev.joomla.org/component/option, ... ase_part1/

However, I will not be the one who adds new information to the database. How do I set this up so that it finds out how many entries there are and will echo all of them out onto the article page?

Re: PHP in Joomla Problems

Posted: Sat Mar 15, 2008 4:10 pm
by radiant_tech
Consider rewriting it as

Code: Select all

$db = &JFactory::getDBO();
$num = 1;
$db->setQuery('SELECT * FROM #__recipe WHERE id = ' . $num);
$row = $db->loadAssocList();

echo $row['title'] . '<br />';
echo $row['ingredients'] . '<br />';
echo $row['directions'] . '<br />';
$row should be an associative array of all the fields in the #__recipe table and their values, so that fields added later can be called by adding a new echo statement for that field.