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?
PHP in Joomla Problems
Moderators: tjay, seadap, Rogue4ngel, matthewhayashida
Forum rules
-
- Joomla! Apprentice
- Posts: 41
- Joined: Sat Dec 15, 2007 3:02 pm
- Location: Washington DC Metro
Re: PHP in Joomla Problems
Consider rewriting it as
$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.
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 />';
Denise