Coding problem ... can you take a look?

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
User avatar
dattard
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Tue Apr 11, 2006 7:29 pm
Contact:

Coding problem ... can you take a look?

Post by dattard » Mon Mar 17, 2008 6:16 pm

Hi,

I'm migrating my Joomla modules to support Joomla 1.5 natively. I'm not an experienced php / Joomla coder, though I've programmed web applications in various languages. I've nearly completed my first one, but I'm having problems accessing the database for some reason. Not sure if I have incorrect syntax or what might be wrong. Is there something wrong with the following code. Its always returning false.

Code: Select all

function &getItems(&$params)
	{
		$db =& JFactory::getDBO();
		$ids		= trim( $params->get('ids') );
		//$sql = 'SELECT id, title FROM '.$db->nameQuote('#__content').' WHERE id in '.$ids;
		$sql = 'SELECT id, title FROM #__content WHERE id in '.$ids;
		echo JText::_($sql);
		if ($instance = $db->loadObjectList())
		{
			return $instance;	
		}
		else
		{
			return false;
		}
	}
Last edited by dattard on Mon Mar 17, 2008 6:20 pm, edited 1 time in total.
http://www.dart-creations.com - We make Joomla Easy: Tutorials, Tips and Tricks, Featured Articles Module, Random Flash Module, Latest News Popup Module, MainMenu Images Module, Popin Window Module

http://www.joomlawire.com - The Joomla DIGG network - Submit and Vote for Joomla News!

User avatar
dattard
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Tue Apr 11, 2006 7:29 pm
Contact:

Re: Coding problem ... can you take a look?

Post by dattard » Mon Mar 17, 2008 6:19 pm

Ok ... that was stupid. I'm missing the setQuery call. This works better:

Code: Select all

function &getItems(&$params)
	{
		$db =& JFactory::getDBO();
		$ids		= trim( $params->get('ids') );
				$sql = 'SELECT id, title FROM #__content WHERE id in '.$ids;
		$db->setQuery($sql);
		if ($instance = $db->loadObjectList())
		{
			return $instance;	
		}
		else
		{
			return false;
		}
	}
http://www.dart-creations.com - We make Joomla Easy: Tutorials, Tips and Tricks, Featured Articles Module, Random Flash Module, Latest News Popup Module, MainMenu Images Module, Popin Window Module

http://www.joomlawire.com - The Joomla DIGG network - Submit and Vote for Joomla News!


Post Reply