1.5 Template Project

The Joomla! Documentation Working Group is running a project to develop detailed reference and tutorial material on Joomla! 1.5 templates.  There is a project page on the documentation wiki where you can see the work in progress and help us by contributing your knowledge.

Who's Online

We have 5 guests online

Help Site License

The Joomla! Help Site content is copyright © 2005 - 2008 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution NonCommercial ShareAlike 2.5. Some parts of this website may be subject to other licenses.
Home arrow Developer Manual arrow 11. API Reference arrow [REVIEW] database->setQuery

[REVIEW] database->setQuery PDF Print E-mail

Last reviewed: Not reviewed
phpDocumentor

database->setQuery

Sets the SQL query string for later execution.  This function also replaces all occurrences within the query string of a given string identifier with the current database table prefix code.  Note that this function does not cause the SQL query to be executed.

Syntax (prior to Joomla 1.0)

void setQuery ( string $query [, string $prefix] )

$query
is the SQL query string.
$prefix
is the string identifier to be replaced by the current database table prefix code.  This parameter is optional and if omitted will default to '#__'.

Syntax (from Joomla 1.0 onwards)

void setQuery ( sting $query [, integer $offset [, integer $limit [, string $prefix ]]] )

$query
is the SQL query string
$offset
is the table row offset for use with page navigation code.  This parameter is optional and if omitted will default to null.
$limit
is the maximum number of rows to be returned by the SQL query.  This parameter is optional and if omitted will default to null.
$prefix
is the string identifier to be replaced by the current database table prefix code.  This parameter is optional and if omitted will default to '#__'.

Examples

Example:

function getCategories() {
  global $database;
 
  $sql = 'SELECT * FROM #__categories';
  $database->setQuery( $sql );
  $rows = $database->loadObjectList();
  foreach ( $rows as $row ) {
    echo "$row->title: $row->description\n";
  }
 
}
 
getCategories();

might produce:

Latest: The latest news from the Joomla Team
Joomla: A selection of links that are all related to the Joomla project.
Newsflash: 
Contacts: Contact Details for this web site
 

Please report any errors on this page to the Developer Documentation Forum.

Last Updated ( Monday, 25 December 2006 )
 
< Prev   Next >