I'm writing a module that incorporates ratings from K2 articles, but when I query the database for this information, I haven't been able to process the results of queries properly. I copied the header and some code from com_K2/models/item.php since that file makes an SQL query for rating data.
Here's the gist of it:
The output is always
"Database prefix is: jos_
Item ID is : Huh?"
It returns the right prefix, so $db must be a good database object. But clearly $db->loadObject() is returning FALSE every time. I've been trying different syntaxes (like "$db->loadObject($row);") and different methods for a couple hours now, so I know I must be missing something. PLEASE help, it's almost there, I just can't see what's wrong.
Here's the gist of it:
<?php
//don't allow other scripts to grab and execute our file
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
jimport('joomla.application.component.model');
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables');
$db = & JFactory::getDBO();
$query = "SELECT * FROM #__k2_rating WHERE 'itemID'=27";
$db->setQuery($query,0,1);
$row = $db->loadObject();
if($row){
$itemID = $row['itemID'];
} else {
$itemID = "Huh?";
}
echo "Database prefix is : " . $db->getPrefix();
echo "Item ID is : " . $itemID;
?>The output is always
"Database prefix is: jos_
Item ID is : Huh?"
It returns the right prefix, so $db must be a good database object. But clearly $db->loadObject() is returning FALSE every time. I've been trying different syntaxes (like "$db->loadObject($row);") and different methods for a couple hours now, so I know I must be missing something. PLEASE help, it's almost there, I just can't see what's wrong.