<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.sandbox.joomla.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rfriedel</id>
	<title>Joomla! Documentation - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.sandbox.joomla.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rfriedel"/>
	<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/Special:Contributions/Rfriedel"/>
	<updated>2026-05-16T07:55:23Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Accessing_the_database_using_JDatabase&amp;diff=14008</id>
		<title>Accessing the database using JDatabase</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Accessing_the_database_using_JDatabase&amp;diff=14008"/>
		<updated>2009-04-24T21:44:22Z</updated>

		<summary type="html">&lt;p&gt;Rfriedel: /* Why should I use the Joomla database class? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Joomla provides a sopisticated database abstraction layer to simplify the usage for 3PD. This guide should help you using this layer.&lt;br /&gt;
&lt;br /&gt;
==Why should I use the Joomla database class?==&lt;br /&gt;
Joomla has been built with the ability to use several different kinds of SQL-database-systems and to run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object, at a minimum, you only need 2 lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
==Preparing the query==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a database object&lt;br /&gt;
$db =&amp;amp; JFactory::getDBO();&lt;br /&gt;
&lt;br /&gt;
$query = &amp;quot;SELECT * FROM #__example_table WHERE id = 999999;&amp;quot;;&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First we instantiate the database object, then we prepare the query. You can use the normal SQL-syntax, the only thing you have to change is the table-prefix. To make this as flexible as possible, Joomla uses a placeholder for the prefix, the &amp;amp;ldquo;#__&amp;amp;rdquo;. In the next step, the $db-&amp;gt;setQuery(), this string is replaced with the correct prefix.&lt;br /&gt;
&lt;br /&gt;
Now, if we don&#039;t want to get information from the database, but insert a row into it, we need one more function. Every string-value in the SQL-syntax should be quoted. For example, MySQL uses backticks &amp;amp;#096;&amp;amp;#096; for names and single quotes &amp;amp;lsquo;&amp;amp;lsquo; for values. Joomla has some functions to do this for us and to ensure code compatibility between different databases. We can pass the names to the function $db-&amp;gt;nameQuote($name) and the values to the function $db-&amp;gt;Quote($value). &lt;br /&gt;
&lt;br /&gt;
A fully quoted query example is:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = &amp;quot;&lt;br /&gt;
  SELECT * &lt;br /&gt;
    FROM &amp;quot;.$db-&amp;gt;nameQuote(&#039;#__example_table&#039;).&amp;quot;  &lt;br /&gt;
    WHERE &amp;quot;.$db-&amp;gt;nameQuote(&#039;id&#039;).&amp;quot; = &amp;quot;.$db-&amp;gt;quote(&#039;999999&#039;).&amp;quot;;&lt;br /&gt;
  &amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whatever we want to do, we have to set the query with the $db-&amp;gt;setQuery() function. Although you could write the query directly as a parameter for $db-&amp;gt;setQuery(), it&#039;s commonly done by first saving it in a variable, normally $query, and then handing this variable over. This helps writing clean, readable code.&lt;br /&gt;
&lt;br /&gt;
==== setQuery($query) ====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;setQuery($query)&#039;&#039; method sets up a database query for later execution either by the query() method or one of the Load result methods.  &amp;lt;pre&amp;gt;$db =&amp;amp; JFactory::getDBO();&lt;br /&gt;
$query = &amp;quot;/* some valid sql string */&amp;quot;;&lt;br /&gt;
$db-&amp;gt;setQuery($query);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
The parameter $query must be a valid sql string, it can either be added as a string parameter or as a variable; generally a variable is preferred as it leads to more legible code and can help in debugging.&lt;br /&gt;
&lt;br /&gt;
setQuery() also takes three other parameters: $offset, $limit - both used in list pagination; and $prefix - an alternative table prefix. All three of these variables have default values set and can usually be ignored. &lt;br /&gt;
&lt;br /&gt;
==Executing the Query==&lt;br /&gt;
To execute the query, Joomla provides several functions, which differ in their return value.&lt;br /&gt;
&lt;br /&gt;
=== Basic Query Execution ===&lt;br /&gt;
&lt;br /&gt;
==== query() ====&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;query()&#039;&#039; method is the the basic tool for executing sql queries on a database. In Joomla it is most often used for updating or administering the database simple because the various load methods detail on this page have the query step built in to them.&lt;br /&gt;
&lt;br /&gt;
The syntax is very straightforward:&amp;lt;pre&amp;gt;$db =&amp;amp; JFactory::getDBO();&lt;br /&gt;
$query = &amp;quot;/* some valid sql string */&amp;quot;;&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$result = $db-&amp;gt;query();&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: $query() returns an appropriate database resource if successful, or FALSE if not&lt;br /&gt;
&lt;br /&gt;
=== Query Execution Information ===&lt;br /&gt;
* getAffectedRows()&lt;br /&gt;
* explain()&lt;br /&gt;
* insertid()&lt;br /&gt;
&lt;br /&gt;
=== Insert Query Execution ===&lt;br /&gt;
* insertObject()&lt;br /&gt;
&lt;br /&gt;
==Query Results ==&lt;br /&gt;
The database class contains many methods for working with a query&#039;s result set.&lt;br /&gt;
&lt;br /&gt;
=== Single Value Result ===&lt;br /&gt;
&lt;br /&gt;
==== loadResult() ====&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;loadResult()&#039;&#039;&#039; when you expect just a single value back from your database query. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! id !! name !! email !! username&lt;br /&gt;
|- &lt;br /&gt;
| 1 || style=&amp;quot;background:yellow&amp;quot; | John Smith || johnsmith@example.com || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || magda_h@example.com || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@example.com || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This is often the result of a &#039;count&#039; query to get a number of records:&lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
$db =&amp;amp; JFactory::getDBO();&lt;br /&gt;
$query = &amp;quot;&lt;br /&gt;
  SELECT COUNT(*)&lt;br /&gt;
    FROM &amp;quot;.$db-&amp;gt;nameQuote(&#039;#__my_table&#039;).&amp;quot;&lt;br /&gt;
    WHERE &amp;quot;.$db-&amp;gt;nameQuote(&#039;name&#039;).&amp;quot; = &amp;quot;.$db-&amp;gt;quote($value).&amp;quot;;&lt;br /&gt;
  &amp;quot;;&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$count = $db-&amp;gt;loadResult();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or where you are just looking for a single field from a single row of the table (or possibly a single field from the first row returned).&lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
$db =&amp;amp; JFactory::getDBO();&lt;br /&gt;
$query = &amp;quot;&lt;br /&gt;
  SELECT &amp;quot;.$db-&amp;gt;nameQuote(&#039;field_name&#039;).&amp;quot;&lt;br /&gt;
    FROM &amp;quot;.$db-&amp;gt;nameQuote(&#039;#__my_table&#039;).&amp;quot;&lt;br /&gt;
    WHERE &amp;quot;.$db-&amp;gt;nameQuote(&#039;some_name&#039;).&amp;quot; = &amp;quot;.$db-&amp;gt;quote($some_value).&amp;quot;;&lt;br /&gt;
  &amp;quot;;&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$result = $db-&amp;gt;loadResult();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Single Row Results ===&lt;br /&gt;
&lt;br /&gt;
Each of these results functions will return a single record from the database even though there may be several records that meet the criteria that you have set. To get more records you need to call the function again.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! id !! name !! email !! username&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 1 || John Smith || johnsmith@example.com || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || magda_h@example.com || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@example.com || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadRow() ====&lt;br /&gt;
&lt;br /&gt;
loadRow() returns an indexed array from a single record in the table: &lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadRow();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; 1 [1] =&amp;gt; John Smith [2] =&amp;gt; johnsmith@example.com [3] =&amp;gt; johnsmith ) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual values by using:&amp;lt;pre&amp;gt;$row[&#039;index&#039;] // e.g. $row[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&lt;br /&gt;
# Whilst you can repeat the call to get further rows, one of the functions that returns multiple rows might be more useful&lt;br /&gt;
&lt;br /&gt;
==== loadAssoc() ====&lt;br /&gt;
&lt;br /&gt;
loadAssoc() returns an associated array from a single record in the table: &lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadRow();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith [email] =&amp;gt; johnsmith@example.com [username] =&amp;gt; johnsmith )&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual values by using:&amp;lt;pre&amp;gt;$row[&#039;name&#039;] // e.g. $row[&#039;name&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# Whilst you can repeat the call to get further rows, one of the functions that returns multiple rows might be more useful&lt;br /&gt;
&lt;br /&gt;
==== loadObject() ====&lt;br /&gt;
&lt;br /&gt;
loadObject returns a PHP object from a single record in the table: &lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$result = $db-&amp;gt;loadObject();&lt;br /&gt;
print_r($result);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;stdClass Object ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith [email] =&amp;gt; johnsmith@example.com [username] =&amp;gt; johnsmith )&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual values by using:&amp;lt;pre&amp;gt;$row-&amp;gt;index // e.g. $row-&amp;gt;email&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# Whilst you can repeat the call to get further rows, one of the functions that returns multiple rows might be more useful&lt;br /&gt;
&lt;br /&gt;
===Single Column Results ===&lt;br /&gt;
&lt;br /&gt;
Each of these results functions will return a single column from the database. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! id !! name !! email !! username&lt;br /&gt;
|- &lt;br /&gt;
| 1 || style=&amp;quot;background:yellow&amp;quot; | John Smith || johnsmith@example.com || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || style=&amp;quot;background:yellow&amp;quot; | Magda Hellman || magda_h@example.com || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || style=&amp;quot;background:yellow&amp;quot; | Yvonne de Gaulle || ydg@example.com || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadResultArray() ====&lt;br /&gt;
&lt;br /&gt;
loadResultArray() returns an indexed array from a single column in the table: &lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
$query = &amp;quot;&lt;br /&gt;
  SELECT name, email, username&lt;br /&gt;
    FROM . . . &amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadResultArray();&lt;br /&gt;
print_r($column);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; John Smith [1] =&amp;gt; Magda Hellman [2] =&amp;gt; Yvonne de Gaulle )&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual values by using:&amp;lt;pre&amp;gt;$column[&#039;index&#039;] // e.g. $column[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&lt;br /&gt;
# loadResultArray() is equivalent to loadResultArray(0)&lt;br /&gt;
&lt;br /&gt;
==== loadResultArray($index) ====&lt;br /&gt;
&lt;br /&gt;
loadResultArray($index) returns an indexed array from a single column in the table: &lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
$query = &amp;quot;&lt;br /&gt;
  SELECT name, email, username&lt;br /&gt;
    FROM . . . &amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadResultArray(2);&lt;br /&gt;
print_r($column);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; johnsmith@example.com [1] =&amp;gt; magda_h@example.com [2] =&amp;gt; ydg@example.com )&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual values by using:&amp;lt;pre&amp;gt;$column[&#039;index&#039;] // e.g. $column[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
loadResultArray($index) allows you to iterate through a series of columns in the results&lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
for ( $i = 0; $i &amp;lt;= 2; $i++ ) {&lt;br /&gt;
  $column= $db-&amp;gt;loadResultArray($i);&lt;br /&gt;
  print_r($column);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; John Smith [1] =&amp;gt; Magda Hellman [2] =&amp;gt; Yvonne de Gaulle )&lt;br /&gt;
Array ( [0] =&amp;gt; johnsmith@example.com [1] =&amp;gt; magda_h@example.com [2] =&amp;gt; ydg@example.com )&lt;br /&gt;
Array ( [0] =&amp;gt; johnsmith [1] =&amp;gt; magdah [2] =&amp;gt; ydegaulle )&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&lt;br /&gt;
&lt;br /&gt;
=== Multi-Row Results ===&lt;br /&gt;
&lt;br /&gt;
Each of these results functions will return multiple records from the database. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! id !! name !! email !! username&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 1 || John Smith || johnsmith@example.com || johnsmith&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 2 || Magda Hellman || magda_h@example.com || magdah&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@example.com || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadRowList() ====&lt;br /&gt;
&lt;br /&gt;
loadRowList() returns an indexed array of indexed arrays from the table records returned by the query: &lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadRowList();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[0] =&amp;gt; Array ( [0] =&amp;gt; 1 [1] =&amp;gt; John Smith [2] =&amp;gt; johnsmith@example.com [3] =&amp;gt; johnsmith ) &lt;br /&gt;
[1] =&amp;gt; Array ( [0] =&amp;gt; 2 [1] =&amp;gt; Magda Hellman [2] =&amp;gt; magda_h@example.com [3] =&amp;gt; magdah ) &lt;br /&gt;
[2] =&amp;gt; Array ( [0] =&amp;gt; 3 [1] =&amp;gt; Yvonne de Gaulle [2] =&amp;gt; ydg@example.com [3] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual rows by using:&amp;lt;pre&amp;gt;$row[&#039;index&#039;] // e.g. $row[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;pre&amp;gt;$row[&#039;index&#039;][&#039;index&#039;] // e.g. $row[&#039;2&#039;][&#039;3&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&lt;br /&gt;
&lt;br /&gt;
==== loadAssocList() ====&lt;br /&gt;
&lt;br /&gt;
loadAssocList() returns an indexed array of associated arrays from the table records returned by the query: &lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadAssocList();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[0] =&amp;gt; Array ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith [email] =&amp;gt; johnsmith@example.com [username] =&amp;gt; johnsmith ) &lt;br /&gt;
[1] =&amp;gt; Array ( [id] =&amp;gt; 2 [name] =&amp;gt; Magda Hellman [email] =&amp;gt; magda_h@example.com [username] =&amp;gt; magdah ) &lt;br /&gt;
[2] =&amp;gt; Array ( [id] =&amp;gt; 3 [name] =&amp;gt; Yvonne de Gaulle [email] =&amp;gt; ydg@example.com [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual rows by using:&amp;lt;pre&amp;gt;$row[&#039;index&#039;] // e.g. $row[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;pre&amp;gt;$row[&#039;index&#039;][&#039;column_name&#039;] // e.g. $row[&#039;2&#039;][&#039;email&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== loadAssocList($key) ====&lt;br /&gt;
&lt;br /&gt;
loadAssocList(&#039;key&#039;) returns an associated array - indexed on &#039;key&#039; - of associated arrays from the table records returned by the query: &lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadAssocList(&#039;username&#039;);&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[johnsmith] =&amp;gt; Array ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith [email] =&amp;gt; johnsmith@example.com [username] =&amp;gt; johnsmith ) &lt;br /&gt;
[magdah] =&amp;gt; Array ( [id] =&amp;gt; 2 [name] =&amp;gt; Magda Hellman [email] =&amp;gt; magda_h@example.com [username] =&amp;gt; magdah ) &lt;br /&gt;
[ydegaulle] =&amp;gt; Array ( [id] =&amp;gt; 3 [name] =&amp;gt; Yvonne de Gaulle [email] =&amp;gt; ydg@example.com [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual rows by using:&amp;lt;pre&amp;gt;$row[&#039;key_value&#039;] // e.g. $row[&#039;johnsmith&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;pre&amp;gt;$row[&#039;key_value&#039;][&#039;column_name&#039;] // e.g. $row[&#039;johnsmith&#039;][&#039;email&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: Key must be a valid column name from the table; it does not have to be an Index or a Primary Key. But if it does not have a unique value you may not be able to retrieve results reliably.&lt;br /&gt;
&lt;br /&gt;
==== loadObjectList() ====&lt;br /&gt;
&lt;br /&gt;
loadObjectList() returns an indexed array of PHP objects from the table records returned by the query: &lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$result = $db-&amp;gt;loadObjectList();&lt;br /&gt;
print_r($result);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[0] =&amp;gt; stdClass Object ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith &lt;br /&gt;
    [email] =&amp;gt; johnsmith@example.com [username] =&amp;gt; johnsmith ) &lt;br /&gt;
[1] =&amp;gt; stdClass Object ( [id] =&amp;gt; 2 [name] =&amp;gt; Magda Hellman &lt;br /&gt;
    [email] =&amp;gt; magda_h@example.com [username] =&amp;gt; magdah ) &lt;br /&gt;
[2] =&amp;gt; stdClass Object ( [id] =&amp;gt; 3 [name] =&amp;gt; Yvonne de Gaulle &lt;br /&gt;
    [email] =&amp;gt; ydg@example.com [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual rows by using:&amp;lt;pre&amp;gt;$row[&#039;index&#039;] // e.g. $row[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;pre&amp;gt;$row[&#039;index&#039;]-&amp;gt;name // e.g. $row[&#039;2&#039;]-&amp;gt;email&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== loadObjectList(&#039;key&#039;) ====&lt;br /&gt;
&lt;br /&gt;
loadObjectList($key) returns an associated array - indexed on &#039;key&#039; - of objects from the table records returned by the query: &lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadObjectList(&#039;username&#039;);&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[johnsmith] =&amp;gt; stdClass Object ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith &lt;br /&gt;
    [email] =&amp;gt; johnsmith@example.com [username] =&amp;gt; johnsmith ) &lt;br /&gt;
[magdah] =&amp;gt; stdClass Object ( [id] =&amp;gt; 2 [name] =&amp;gt; Magda Hellman &lt;br /&gt;
    [email] =&amp;gt; magda_h@example.com [username] =&amp;gt; magdah ) &lt;br /&gt;
[ydegaulle] =&amp;gt; stdClass Object ( [id] =&amp;gt; 3 [name] =&amp;gt; Yvonne de Gaulle &lt;br /&gt;
    [email] =&amp;gt; ydg@example.com [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual rows by using:&amp;lt;pre&amp;gt;$row[&#039;key_value&#039;] // e.g. $row[&#039;johnsmith&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;pre&amp;gt;$row[&#039;key_value&#039;]-&amp;gt;column_name // e.g. $row[&#039;johnsmith&#039;]-&amp;gt;email&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: Key must be a valid column name from the table; it does not have to be an Index or a Primary Key. But if it does not have a unique value you may not be able to retrieve results reliably.&lt;br /&gt;
&lt;br /&gt;
=== Misc Result Set Methods ===&lt;br /&gt;
&lt;br /&gt;
==== getNumRows() ====&lt;br /&gt;
&lt;br /&gt;
getNumRows() will return the number of result rows found by the last query and waiting to be read. To get a result from getNumRows() you have to run it &#039;&#039;&#039;after&#039;&#039;&#039; the query and &#039;&#039;&#039;before&#039;&#039;&#039; you have retrieved any results.  &lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$db-&amp;gt;query();&lt;br /&gt;
$num_rows = $db-&amp;gt;getNumRows();&lt;br /&gt;
print_r($num_rows);&lt;br /&gt;
$result = $db-&amp;gt;loadResultList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return &amp;lt;pre&amp;gt;3&amp;lt;/pre&amp;gt;&lt;br /&gt;
Note: if you run getNumRows() after loadResultList() - or any other retrieval method - you may get a PHP Warning:&lt;br /&gt;
&amp;lt;pre&amp;gt;Warning: mysql_num_rows(): 80 is not a valid MySQL result resource &lt;br /&gt;
in D:\xampp\htdocs\joomla1.5a\libraries\joomla\database\database\mysql.php on line 344&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tips, Tricks &amp;amp; FAQ==&lt;br /&gt;
We had a few people lately using sub-queries like these:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;SQL&amp;quot;&amp;gt;&lt;br /&gt;
SELECT * FROM #__example WHERE id IN (SELECT * FROM #__example2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
These kind of queries are only possible in MySQL 4.1 and above. Another way to achieve this, is splitting the query into two:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = &amp;quot;SELECT * FROM #__example2&amp;quot;;&lt;br /&gt;
$database-&amp;gt;setQuery($query);&lt;br /&gt;
$query = &amp;quot;SELECT * FROM #__example WHERE id IN (&amp;quot;. implode(&amp;quot;,&amp;quot;, $database-&amp;gt;loadArray()) .&amp;quot;)&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;noinclude&amp;gt;[[Category:Development]][[Category:Database]]&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rfriedel</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=How_to_find_your_absolute_path&amp;diff=12732</id>
		<title>How to find your absolute path</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=How_to_find_your_absolute_path&amp;diff=12732"/>
		<updated>2009-01-15T08:29:20Z</updated>

		<summary type="html">&lt;p&gt;Rfriedel: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Using Joomla Find Your Absolute Path ==&lt;br /&gt;
&lt;br /&gt;
=== What is the absolute path? ===&lt;br /&gt;
The absolute path is the directory location on a server&#039;s hard drive where Joomla! is located. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Joomla! 1.0.x ===&lt;br /&gt;
In Joomla! v.1.0.x the configuration.php file would be something like the following, however, it can vary depending on your server.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;$mosConfig_absolute_path = &#039;/home/joomla/public_html&#039;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Usage ====&lt;br /&gt;
To find out what your absolute path is&amp;lt;ref&amp;gt;[http://www.joomlatutorials.com/faq/view/joomla_beginner/what_is_my_absolute_path?/60.html Finding your absolute path in Joomla! 1.0.x] Joomlatutorials&amp;lt;/ref&amp;gt;, copy the following code into a text editor (i.e. Notepad, TextEdit etc), save the file as a .php naming it whatever you want (i.e anyfilename.php.).&lt;br /&gt;
&lt;br /&gt;
Using your FTP software, ftp the file you have just created to your root folder. Open a web browser and type in http://www.yourdomain.com/filename.php.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
    $path = getcwd();&lt;br /&gt;
    echo &amp;quot;Your Absoluthe Path is: &amp;quot;;&lt;br /&gt;
    echo $path;&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;IMPORTANT: For security reasons, delete this file as soon as you have ascertained the information you require.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Joomla! 1.5.x ===&lt;br /&gt;
In Joomla! v.1.5.x the absolute path is set in the index.php (&amp;lt;small&amp;gt;line 17&amp;lt;/small&amp;gt;) file in the base directory to the constant [[JPATH_BASE]].&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;define(&#039;JPATH_BASE&#039;, dirname(__FILE__) );&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Usage ====&lt;br /&gt;
Use the constant [[JPATH_BASE]]. This constant returns the absolute path to your Joomla! installation directory.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
    echo JPATH_BASE;&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== See Also ===&lt;br /&gt;
[http://forum.joomla.org/viewtopic.php?t=1035 Absolute Path for Joomla! 1.0.x]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== References ===&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Tips and tricks]]&lt;br /&gt;
[[Category:Tips and tricks 1.0]]&lt;br /&gt;
[[Category:Tips and tricks 1.5]]&lt;/div&gt;</summary>
		<author><name>Rfriedel</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Adding_JavaScript&amp;diff=12729</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Adding_JavaScript&amp;diff=12729"/>
		<updated>2009-01-15T06:46:37Z</updated>

		<summary type="html">&lt;p&gt;Rfriedel: /* Adding Javascript Files Using JHTML */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{cookiejar}}&lt;br /&gt;
===Adding JavaScript===&lt;br /&gt;
----&lt;br /&gt;
This chunk should describe in detail how to add JavaScript to the head of&lt;br /&gt;
a template using the Joomla! 1.5 API calls. It should be aimed at&lt;br /&gt;
people who have only minimal knowledge of PHP, HTML and JavaScript.&lt;br /&gt;
----&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
&lt;br /&gt;
Add the following code to have the javascript library /media/system/js/sample.js included in your template.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 $document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
 $document-&amp;gt;addScript( &#039;/media/system/js/sample.js&#039; );&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
&lt;br /&gt;
Ultimately you are trying to have the resulting HTML page have in the &amp;lt;head&amp;gt; ... &amp;lt;/head&amp;gt; area have a javascript include:&lt;br /&gt;
&lt;br /&gt;
For Example:&lt;br /&gt;
 &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ensure that the javascript you want to include is in the directory,  from the above example:&lt;br /&gt;
 /media/system/js/sample.js&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When you are able to load both your page and see the &amp;lt;script&amp;gt; tag in the &amp;lt;head&amp;gt; area, and be able to load the javascript from the address&lt;br /&gt;
&lt;br /&gt;
Again, using the example: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;http://www.example.com/media/system/js/sample.js&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the script is integrated into your page, and you can proceed to using javascript in your HTML.&lt;br /&gt;
&lt;br /&gt;
Do not directly add the &amp;lt;script&amp;gt; to your template&#039;s index.php.&lt;br /&gt;
&lt;br /&gt;
The code will insert the the &amp;lt;script&amp;gt; line where your index.php has the following line:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;jdoc:include type=&amp;quot;head&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add this PHP code to your page, in the head, or next to the javascript code you will use, depending on your preference.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 $document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
 $document-&amp;gt;addScript( &#039;/media/system/js/sample.js&#039; );&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
Reload your template and view the page, and ensure that the sample.js is included in the &amp;lt;head&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding Javascript Files Using JHTML ==&lt;br /&gt;
&lt;br /&gt;
You may also use the [http://api.joomla.org/Joomla-Framework/HTML/JHTML.html JHTML] [http://api.joomla.org/Joomla-Framework/HTML/JHTML.html#script script] method to add a javascript file to the head of your document.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
    $filename = &#039;path/to/file/filename.js&#039;;&lt;br /&gt;
    JHTML::script($filename);&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There is a second parameter that can be passed to the script method. The parameter is a boolean (true/false). You would set this to true if you wanted MooTools loaded as well.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
    $filename = &#039;path/to/file/filename.js&#039;;&lt;br /&gt;
    JHTML::script($filename, true); // MooTools will load if it is not already loaded&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Please Note: Joomla 1.6+ may or may not handle MooTools differently than in previous versions.&#039;&#039;&#039;&amp;lt;ref&amp;gt;[http://forum.joomla.org/viewtopic.php?f=502&amp;amp;t=273960 Whitepaper] Upgrade to mootools 1.2&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rfriedel</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Adding_JavaScript&amp;diff=12728</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Adding_JavaScript&amp;diff=12728"/>
		<updated>2009-01-15T06:46:10Z</updated>

		<summary type="html">&lt;p&gt;Rfriedel: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{cookiejar}}&lt;br /&gt;
===Adding JavaScript===&lt;br /&gt;
----&lt;br /&gt;
This chunk should describe in detail how to add JavaScript to the head of&lt;br /&gt;
a template using the Joomla! 1.5 API calls. It should be aimed at&lt;br /&gt;
people who have only minimal knowledge of PHP, HTML and JavaScript.&lt;br /&gt;
----&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
&lt;br /&gt;
Add the following code to have the javascript library /media/system/js/sample.js included in your template.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 $document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
 $document-&amp;gt;addScript( &#039;/media/system/js/sample.js&#039; );&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
&lt;br /&gt;
Ultimately you are trying to have the resulting HTML page have in the &amp;lt;head&amp;gt; ... &amp;lt;/head&amp;gt; area have a javascript include:&lt;br /&gt;
&lt;br /&gt;
For Example:&lt;br /&gt;
 &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ensure that the javascript you want to include is in the directory,  from the above example:&lt;br /&gt;
 /media/system/js/sample.js&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When you are able to load both your page and see the &amp;lt;script&amp;gt; tag in the &amp;lt;head&amp;gt; area, and be able to load the javascript from the address&lt;br /&gt;
&lt;br /&gt;
Again, using the example: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;http://www.example.com/media/system/js/sample.js&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the script is integrated into your page, and you can proceed to using javascript in your HTML.&lt;br /&gt;
&lt;br /&gt;
Do not directly add the &amp;lt;script&amp;gt; to your template&#039;s index.php.&lt;br /&gt;
&lt;br /&gt;
The code will insert the the &amp;lt;script&amp;gt; line where your index.php has the following line:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;jdoc:include type=&amp;quot;head&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add this PHP code to your page, in the head, or next to the javascript code you will use, depending on your preference.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 $document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
 $document-&amp;gt;addScript( &#039;/media/system/js/sample.js&#039; );&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
Reload your template and view the page, and ensure that the sample.js is included in the &amp;lt;head&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding Javascript Files Using JHTML ==&lt;br /&gt;
&lt;br /&gt;
You may also use the [http://api.joomla.org/Joomla-Framework/HTML/JHTML.html JHTML] [http://api.joomla.org/Joomla-Framework/HTML/JHTML.html#script script] method to add a javascript file to the head of your document.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
    $filename = &#039;path/to/file/filename.js&#039;;&lt;br /&gt;
    JHTML::script($filename);&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There is a second parameter that can be passed to the script method. The parameter is a boolean (true/false). You would set this to true if you wanted MooTools loaded as well.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
    $filename = &#039;path/to/file/filename.js&#039;;&lt;br /&gt;
    JHTML::script($filename, true); // MooTools will load if it is not already loaded&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;Please Note: Joomla 1.6+ may or may not handle MooTools differently than in previous versions.&#039;&#039;&#039;&#039;&amp;lt;ref&amp;gt;[http://forum.joomla.org/viewtopic.php?f=502&amp;amp;t=273960 Whitepaper] Upgrade to mootools 1.2&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rfriedel</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Adding_JavaScript&amp;diff=12727</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Adding_JavaScript&amp;diff=12727"/>
		<updated>2009-01-15T06:44:51Z</updated>

		<summary type="html">&lt;p&gt;Rfriedel: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{cookiejar}}&lt;br /&gt;
===Adding JavaScript===&lt;br /&gt;
----&lt;br /&gt;
This chunk should describe in detail how to add JavaScript to the head of&lt;br /&gt;
a template using the Joomla! 1.5 API calls. It should be aimed at&lt;br /&gt;
people who have only minimal knowledge of PHP, HTML and JavaScript.&lt;br /&gt;
----&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
&lt;br /&gt;
Add the following code to have the javascript library /media/system/js/sample.js included in your template.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 $document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
 $document-&amp;gt;addScript( &#039;/media/system/js/sample.js&#039; );&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
&lt;br /&gt;
Ultimately you are trying to have the resulting HTML page have in the &amp;lt;head&amp;gt; ... &amp;lt;/head&amp;gt; area have a javascript include:&lt;br /&gt;
&lt;br /&gt;
For Example:&lt;br /&gt;
 &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ensure that the javascript you want to include is in the directory,  from the above example:&lt;br /&gt;
 /media/system/js/sample.js&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When you are able to load both your page and see the &amp;lt;script&amp;gt; tag in the &amp;lt;head&amp;gt; area, and be able to load the javascript from the address&lt;br /&gt;
&lt;br /&gt;
Again, using the example: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;http://www.example.com/media/system/js/sample.js&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the script is integrated into your page, and you can proceed to using javascript in your HTML.&lt;br /&gt;
&lt;br /&gt;
Do not directly add the &amp;lt;script&amp;gt; to your template&#039;s index.php.&lt;br /&gt;
&lt;br /&gt;
The code will insert the the &amp;lt;script&amp;gt; line where your index.php has the following line:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;jdoc:include type=&amp;quot;head&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add this PHP code to your page, in the head, or next to the javascript code you will use, depending on your preference.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 $document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
 $document-&amp;gt;addScript( &#039;/media/system/js/sample.js&#039; );&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
Reload your template and view the page, and ensure that the sample.js is included in the &amp;lt;head&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding Javascript Files Using JHTML ==&lt;br /&gt;
&lt;br /&gt;
You may also use the [http://api.joomla.org/Joomla-Framework/HTML/JHTML.html JHTML] [http://api.joomla.org/Joomla-Framework/HTML/JHTML.html#script script] method to add a javascript file to the head of your document.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
    $filename = &#039;path/to/file/filename.js&#039;;&lt;br /&gt;
    JHTML::script($filename);&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There is a second parameter that can be passed to the script method. The parameter is a boolean (true/false). You would set this to true if you wanted MooTools loaded as well.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
    $filename = &#039;path/to/file/filename.js&#039;;&lt;br /&gt;
    JHTML::script($filename, true); // MooTools will load if it is not already loaded&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Please Note: Joomla 1.6+ may or may not handle MooTools differently than in previous versions.&#039;&#039;&#039;&amp;lt;ref name=&amp;quot;MooToolsUpdate&amp;quot;&amp;gt;[http://forum.joomla.org/viewtopic.php?f=502&amp;amp;t=273960 Whitepaper] Upgrade to mootools 1.2 whitepaper&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rfriedel</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Adding_JavaScript&amp;diff=12726</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Adding_JavaScript&amp;diff=12726"/>
		<updated>2009-01-15T06:33:06Z</updated>

		<summary type="html">&lt;p&gt;Rfriedel: /* Adding Javascript Files Using JHTML */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{cookiejar}}&lt;br /&gt;
===Adding JavaScript===&lt;br /&gt;
----&lt;br /&gt;
This chunk should describe in detail how to add JavaScript to the head of&lt;br /&gt;
a template using the Joomla! 1.5 API calls. It should be aimed at&lt;br /&gt;
people who have only minimal knowledge of PHP, HTML and JavaScript.&lt;br /&gt;
----&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following code to have the javascript library /media/system/js/sample.js included in your template.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 $document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
 $document-&amp;gt;addScript( &#039;/media/system/js/sample.js&#039; );&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Explanation===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Ultimately you are trying to have the resulting HTML page have in the &amp;lt;head&amp;gt; ... &amp;lt;/head&amp;gt; area have a javascript include:&lt;br /&gt;
&lt;br /&gt;
For Example:&lt;br /&gt;
 &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ensure that the javascript you want to include is in the directory,  from the above example:&lt;br /&gt;
 /media/system/js/sample.js&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When you are able to load both your page and see the &amp;lt;script&amp;gt; tag in the &amp;lt;head&amp;gt; area, and be able to load the javascript from the address&lt;br /&gt;
&lt;br /&gt;
Again, using the example: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;http://www.example.com/media/system/js/sample.js&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the script is integrated into your page, and you can proceed to using javascript in your HTML.&lt;br /&gt;
&lt;br /&gt;
Do not directly add the &amp;lt;script&amp;gt; to your template&#039;s index.php.&lt;br /&gt;
&lt;br /&gt;
The code will insert the the &amp;lt;script&amp;gt; line where your index.php has the following line:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;jdoc:include type=&amp;quot;head&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add this PHP code to your page, in the head, or next to the javascript code you will use, depending on your preference.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 $document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
 $document-&amp;gt;addScript( &#039;/media/system/js/sample.js&#039; );&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
Reload your template and view the page, and ensure that the sample.js is included in the &amp;lt;head&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding Javascript Files Using JHTML ==&lt;br /&gt;
&lt;br /&gt;
You may also use the [http://api.joomla.org/Joomla-Framework/HTML/JHTML.html JHTML] [http://api.joomla.org/Joomla-Framework/HTML/JHTML.html#script script] method to add a javascript file to the head of your document.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
    $filename = &#039;path/to/file/filename.js&#039;;&lt;br /&gt;
    JHTML::script($filename);&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There is a second parameter that can be passed to the script method. The parameter is a boolean (true/false). You would set this to true if you wanted MooTools loaded as well.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
    $filename = &#039;path/to/file/filename.js&#039;;&lt;br /&gt;
    JHTML::script($filename, true); // MooTools will load if it is not already loaded&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Please Note: Joomla 1.6+ may or may not handle MooTools differently than in previous versions.&#039;&#039;&#039;&amp;lt;ref name=&amp;quot;Whitepaper&amp;quot;&amp;gt;[http://forum.joomla.org/viewtopic.php?f=502&amp;amp;t=273960 Whitepaper] Upgrade to mootools 1.2&lt;/div&gt;</summary>
		<author><name>Rfriedel</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Adding_JavaScript&amp;diff=12725</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Adding_JavaScript&amp;diff=12725"/>
		<updated>2009-01-15T05:55:08Z</updated>

		<summary type="html">&lt;p&gt;Rfriedel: Added the JHTML method of loading a js file&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{cookiejar}}&lt;br /&gt;
===Adding JavaScript===&lt;br /&gt;
----&lt;br /&gt;
This chunk should describe in detail how to add JavaScript to the head of&lt;br /&gt;
a template using the Joomla! 1.5 API calls. It should be aimed at&lt;br /&gt;
people who have only minimal knowledge of PHP, HTML and JavaScript.&lt;br /&gt;
----&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following code to have the javascript library /media/system/js/sample.js included in your template.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 $document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
 $document-&amp;gt;addScript( &#039;/media/system/js/sample.js&#039; );&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Explanation===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Ultimately you are trying to have the resulting HTML page have in the &amp;lt;head&amp;gt; ... &amp;lt;/head&amp;gt; area have a javascript include:&lt;br /&gt;
&lt;br /&gt;
For Example:&lt;br /&gt;
 &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ensure that the javascript you want to include is in the directory,  from the above example:&lt;br /&gt;
 /media/system/js/sample.js&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When you are able to load both your page and see the &amp;lt;script&amp;gt; tag in the &amp;lt;head&amp;gt; area, and be able to load the javascript from the address&lt;br /&gt;
&lt;br /&gt;
Again, using the example: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;http://www.example.com/media/system/js/sample.js&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the script is integrated into your page, and you can proceed to using javascript in your HTML.&lt;br /&gt;
&lt;br /&gt;
Do not directly add the &amp;lt;script&amp;gt; to your template&#039;s index.php.&lt;br /&gt;
&lt;br /&gt;
The code will insert the the &amp;lt;script&amp;gt; line where your index.php has the following line:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;jdoc:include type=&amp;quot;head&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add this PHP code to your page, in the head, or next to the javascript code you will use, depending on your preference.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 $document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
 $document-&amp;gt;addScript( &#039;/media/system/js/sample.js&#039; );&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
Reload your template and view the page, and ensure that the sample.js is included in the &amp;lt;head&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding Javascript Files Using JHTML ==&lt;br /&gt;
&lt;br /&gt;
You may also use the [http://api.joomla.org/Joomla-Framework/HTML/JHTML.html JHTML] [http://api.joomla.org/Joomla-Framework/HTML/JHTML.html#script script] method to add a javascript file to the head of your document.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
    $filename = &#039;path/to/file/filename.js&#039;;&lt;br /&gt;
    JHTML::script($filename);&lt;br /&gt;
 ?&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rfriedel</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Cannot_save_Global_Configuration_changes&amp;diff=10534</id>
		<title>Cannot save Global Configuration changes</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Cannot_save_Global_Configuration_changes&amp;diff=10534"/>
		<updated>2008-09-04T14:18:56Z</updated>

		<summary type="html">&lt;p&gt;Rfriedel: Added category FAQ&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:FAQ]]&lt;br /&gt;
&lt;br /&gt;
{{cookiejar}}&lt;br /&gt;
{{stub}}&lt;br /&gt;
This problem is usually caused by incorrect ownership or permissions on the &#039;&#039;configuration.php&#039;&#039; file which is where the Global Configuration settings are stored.  On some Joomla! installations the &#039;&#039;configuration.php&#039;&#039; file is set to read-only as an additional security measure.&lt;/div&gt;</summary>
		<author><name>Rfriedel</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Talk:Cannot_save_Global_Configuration_changes&amp;diff=10533</id>
		<title>Talk:Cannot save Global Configuration changes</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Talk:Cannot_save_Global_Configuration_changes&amp;diff=10533"/>
		<updated>2008-09-04T14:17:43Z</updated>

		<summary type="html">&lt;p&gt;Rfriedel: New page: Should this be in the FAQ page?&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Should this be in the FAQ page?&lt;/div&gt;</summary>
		<author><name>Rfriedel</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Talk:JUser_example&amp;diff=10529</id>
		<title>Talk:JUser example</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Talk:JUser_example&amp;diff=10529"/>
		<updated>2008-09-04T13:14:18Z</updated>

		<summary type="html">&lt;p&gt;Rfriedel: Talk:JUser example moved to Talk:JUser: Should be a subheader under JUser&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Talk:JUser]]&lt;/div&gt;</summary>
		<author><name>Rfriedel</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Talk:JUser&amp;diff=10528</id>
		<title>Talk:JUser</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Talk:JUser&amp;diff=10528"/>
		<updated>2008-09-04T13:14:18Z</updated>

		<summary type="html">&lt;p&gt;Rfriedel: Talk:JUser example moved to Talk:JUser: Should be a subheader under JUser&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Good start, but this needs to be expanded and improved.  I suggest the following:&lt;br /&gt;
# Don&#039;t use acronyms like &amp;quot;DB&amp;quot; for &amp;quot;database&amp;quot; and so on.&lt;br /&gt;
# Code should follow [http://docs.joomla.org/Coding_style_and_standards Coding Standards] as it needs to set a good example.&lt;br /&gt;
# Don&#039;t introduce functions that are not part of the Joomla! Framework or Joomla! CMS (MRender in this case).&lt;br /&gt;
# Do try to explain clearly what the code does (and what problem it solves) without assuming that the reader has extensive understanding of Joomla! itself.&lt;br /&gt;
# Do try to use descriptive variable names (eg. maybe &amp;quot;$user&amp;quot; instead of &amp;quot;$NU&amp;quot;).&lt;br /&gt;
# Do try to include any jimport statements if these are required.&lt;br /&gt;
[[User:Chris Davenport|Chris Davenport]] 15:45, 7 April 2008 (EDT)&lt;/div&gt;</summary>
		<author><name>Rfriedel</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=What%27s_available_in_the_JFactory_class&amp;diff=10522</id>
		<title>What&#039;s available in the JFactory class</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=What%27s_available_in_the_JFactory_class&amp;diff=10522"/>
		<updated>2008-09-04T12:56:52Z</updated>

		<summary type="html">&lt;p&gt;Rfriedel: What&amp;#039;s available in the JFactory class moved to JFactory Class: The page as it was should be a subheader under the JFactory page. Renamed it to &amp;#039;JFactory Class&amp;#039; because I couldn&amp;#039;t name it to &amp;#039;JFactory&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[JFactory Class]]&lt;/div&gt;</summary>
		<author><name>Rfriedel</name></author>
	</entry>
</feed>