setQuery() function explained

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
CasperNH
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Thu Jun 04, 2009 9:04 am

setQuery() function explained

Post by CasperNH » Wed Mar 24, 2010 4:41 pm

Hi,

Im new with coding and extension development. I have this code for a module, but some of these lines dont make sense.

Code: Select all

$items = $params->get('items', 1);
$db =& JFactory::getDBO();
$query = "SELECT id, name FROM #__reviews WHERE published = '1' ORDER BY review_date DESC";
$db->setQuery( $query, 0, $items );
$rows = $db->loadObjectList();
foreach($rows as $row)
{
echo '<a href="' . JRoute::_('index.php?option=com_reviews&id='
. $row->id . '&task=view') . '">' . $row->name .
'</a><br />';
}
?>
1. What are the purpose of Setquery? (and what are the parameters inside for?)

Hope you can help me with this.

webinsert
Joomla! Apprentice
Joomla! Apprentice
Posts: 34
Joined: Mon Nov 10, 2008 1:21 pm

Re: setQuery() function explained

Post by webinsert » Wed Mar 24, 2010 8:17 pm

File database.php explains:

/**
* Sets the SQL query string for later execution.
*
* This function replaces a string identifier <var>$prefix</var> with the
* string held is the <var>_table_prefix</var> class variable.
*
* @access public
* @param string The SQL query
* @param string The offset to start selection
* @param string The number of results to return
* @param string The common table prefix
*/
function setQuery( $sql, $offset = 0, $limit = 0, $prefix='#__' )
{
$this->_sql = $this->replacePrefix( $sql, $prefix );
$this->_limit = (int) $limit;
$this->_offset = (int) $offset;
}


Locked

Return to “Joomla! 1.5 Coding”