PHP in Joomla Problems

Discussion and education for beginner / novice programmers interested in embarking on the development process to take advantage of the extensible nature of the Joomla! CMS.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Forum rules
Post Reply
Plaidfox
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Fri Feb 08, 2008 5:17 pm

PHP in Joomla Problems

Post by Plaidfox » Fri Feb 29, 2008 8:53 pm

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?

radiant_tech
Joomla! Apprentice
Joomla! Apprentice
Posts: 41
Joined: Sat Dec 15, 2007 3:02 pm
Location: Washington DC Metro

Re: PHP in Joomla Problems

Post by radiant_tech » Sat Mar 15, 2008 4:10 pm

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.
Denise


Post Reply