<?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=AndyGaskell</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=AndyGaskell"/>
	<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/Special:Contributions/AndyGaskell"/>
	<updated>2026-10-12T16:52:52Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=783945</id>
		<title>Selecting data using JDatabase</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=783945"/>
		<updated>2021-02-25T11:29:57Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;&amp;lt;languages /&amp;gt;&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&amp;lt;noinclude&amp;gt;{{Joomla version|version=3.x}}{{Joomla version|version=2.5|status=eos}}&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
{{-}}&lt;br /&gt;
{{tip|&amp;lt;translate&amp;gt;&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
Note many examples online use &amp;lt;code&amp;gt;$db-&amp;gt;query()&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;$db-&amp;gt;execute()&amp;lt;/code&amp;gt;. This was the old method in Joomla 1.5 and 2.5 and will throw a deprecated notice in Joomla 3.0+.&amp;lt;/translate&amp;gt;|title=&amp;lt;translate&amp;gt;&amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
Version Note&amp;lt;/translate&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
This tutorial is split into two independent parts:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
* Inserting, updating and removing data from the database.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
* Selecting data from one or more tables and retrieving it in a variety of different forms&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
This section of the documentation looks at selecting data from a database table and retrieving it in a variety of formats. To see the other part [[S:MyLanguage/Inserting,_Updating_and_Removing_data_using_JDatabase|click here]]&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Introduction== &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
Joomla can use different kinds of SQL database systems and 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 you need just two 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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==The Query== &amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
Joomla&#039;s database querying changed with the introduction of Joomla 1.6. The recommended way of building database queries is through &amp;quot;query chaining&amp;quot; (although string queries are still supported).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source&#039;s query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer&#039;s source code.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code&amp;lt;/translate&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==Selecting Records from a Single Table== &amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
Below is an example of creating a database query using the &amp;lt;tt&amp;gt;JDatabaseQuery&amp;lt;/tt&amp;gt; class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)));&lt;br /&gt;
$query-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;));&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;custom.%&#039;));&lt;br /&gt;
$query-&amp;gt;order(&#039;ordering ASC&#039;);&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects (see later for more options on retrieving data).&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Here the &amp;lt;tt&amp;gt;quoteName()&amp;lt;/tt&amp;gt; function adds appropriate quotes around the column names to avoid conflicts with any database reserved word, now or in the future.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:19--&amp;gt;&lt;br /&gt;
The query can also be chained to simplify further:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;custom.%&#039;))&lt;br /&gt;
    -&amp;gt;order(&#039;ordering ASC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
Chaining method calls improves code readability and reduces code bloat as queries become longer and more complex.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
Grouping can be achieved simply too.  The following query would count the number of articles in each category.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array(&#039;catid&#039;, &#039;COUNT(*)&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;))&lt;br /&gt;
    -&amp;gt;group($db-&amp;gt;quoteName(&#039;catid&#039;));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
A limit can be set to a query using &amp;quot;setLimit&amp;quot;. For example in the following query, it would return up to 10 records.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;))&lt;br /&gt;
    -&amp;gt;setLimit(&#039;10&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Selecting Records from Multiple Tables== &amp;lt;!--T:23--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:24--&amp;gt;&lt;br /&gt;
Using the JDatabaseQuery&#039;s [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with &#039;a&#039;.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
// Note by putting &#039;a&#039; as a second parameter will generate `#__content` AS `a`&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;a%&#039;))&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects (see later for more options on retrieving data).&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for joins:&amp;lt;/translate&amp;gt;&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_innerJoin innerJoin()]&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_leftJoin leftJoin()]&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_rightJoin rightJoin()] &lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_outerJoin outerJoin()]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:26--&amp;gt;&lt;br /&gt;
We can use multiple joins to query across more than two tables:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;, &#039;c.*&#039;, &#039;d.*&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;LEFT&#039;, $db-&amp;gt;quoteName(&#039;#__user_profiles&#039;, &#039;c&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;c.user_id&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;RIGHT&#039;, $db-&amp;gt;quoteName(&#039;#__categories&#039;, &#039;d&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.catid&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;d.id&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;a%&#039;))&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:27--&amp;gt;&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:28--&amp;gt;&lt;br /&gt;
In some cases, you will also need to use the AS clause when selecting items to avoid column name conflicts. In this case, multiple select statements can be chained in conjunction with using the second parameter of $db-&amp;gt;quoteName.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(&#039;a.*&#039;)&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(&#039;b.username&#039;, &#039;username&#039;))&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(&#039;b.name&#039;, &#039;name&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;a%&#039;))&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:29--&amp;gt;&lt;br /&gt;
A second array can also be used as the second parameter of the select statement to populate the values of the AS clause. Remember to include nulls in the second array to correspond to columns in the first array that you don&#039;t want to use the AS clause for:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array(&#039;a.*&#039;))&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;b.username&#039;, &#039;b.name&#039;), array(&#039;username&#039;, &#039;name&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;a%&#039;))&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==Using OR in queries== &amp;lt;!--T:140--&amp;gt; &amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:141--&amp;gt;&lt;br /&gt;
When using multiple WHERE clauses in your query, they will be treated as an AND.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:142--&amp;gt;&lt;br /&gt;
So, for example, the query below will return results where the &#039;name&#039; field AND the &#039;state&#039; field match.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;COUNT(*)&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($value)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;state&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($state));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:143--&amp;gt;&lt;br /&gt;
To use a WHERE clause as an OR, the query can be written like this&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;COUNT(*)&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($name_one), &#039;OR&#039;)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($name_two));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:144--&amp;gt;&lt;br /&gt;
it can also be written like this&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;COUNT(*)&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($name_one)&lt;br /&gt;
    -&amp;gt;orWhere($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($name_two));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==Query Results == &amp;lt;!--T:30--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:31--&amp;gt;&lt;br /&gt;
The database class contains many methods for working with a query&#039;s result set.&lt;br /&gt;
&lt;br /&gt;
If there are no matches to the query, the result will be null.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Single Value Result === &amp;lt;!--T:32--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadResult() ==== &amp;lt;!--T:33--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:34--&amp;gt;&lt;br /&gt;
Use &#039;&#039;&#039;loadResult()&#039;&#039;&#039; when you expect just a single value back from your database query.&amp;lt;/translate&amp;gt; &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;
! &amp;lt;translate&amp;gt;&amp;lt;!--T:35--&amp;gt;&lt;br /&gt;
id&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:36--&amp;gt;&lt;br /&gt;
name&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:37--&amp;gt;&lt;br /&gt;
email&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:38--&amp;gt;&lt;br /&gt;
username&amp;lt;/translate&amp;gt;&lt;br /&gt;
|- &lt;br /&gt;
| 1 || style=&amp;quot;background:yellow&amp;quot; | John Smith || &amp;lt;translate&amp;gt;&amp;lt;!--T:39--&amp;gt;&lt;br /&gt;
johnsmith@domain.example&amp;lt;/translate&amp;gt; || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || &amp;lt;translate&amp;gt;&amp;lt;!--T:40--&amp;gt;&lt;br /&gt;
magda_h@domain.example&amp;lt;/translate&amp;gt; || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || &amp;lt;translate&amp;gt;&amp;lt;!--T:41--&amp;gt;&lt;br /&gt;
ydg@domain.example&amp;lt;/translate&amp;gt; || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:42--&amp;gt;&lt;br /&gt;
This is often the result of a &#039;count&#039; query to get a number of records:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;COUNT(*)&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($value));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:134--&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).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;field_name&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;some_name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($some_value));&lt;br /&gt;
&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;
&amp;lt;translate&amp;gt;&lt;br /&gt;
===Single Row Results === &amp;lt;!--T:43--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:44--&amp;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.&amp;lt;/translate&amp;gt;&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;
! &amp;lt;translate&amp;gt;&amp;lt;!--T:45--&amp;gt;&lt;br /&gt;
id&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:46--&amp;gt;&lt;br /&gt;
name&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:47--&amp;gt;&lt;br /&gt;
email&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:48--&amp;gt;&lt;br /&gt;
username&amp;lt;/translate&amp;gt;&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 1 || John Smith || &amp;lt;translate&amp;gt;&amp;lt;!--T:49--&amp;gt;&lt;br /&gt;
johnsmith@domain.example&amp;lt;/translate&amp;gt; || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || &amp;lt;translate&amp;gt;&amp;lt;!--T:50--&amp;gt;&lt;br /&gt;
magda_h@domain.example&amp;lt;/translate&amp;gt; || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || &amp;lt;translate&amp;gt;&amp;lt;!--T:51--&amp;gt;&lt;br /&gt;
ydg@domain.example&amp;lt;/translate&amp;gt; || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadRow() ==== &amp;lt;!--T:52--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:53--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadRow()&amp;lt;/tt&amp;gt; returns an indexed array from a single record in the table:&amp;lt;/translate&amp;gt; &lt;br /&gt;
&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:133--&amp;gt;&lt;br /&gt;
will give:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; 1, [1] =&amp;gt; John Smith, [2] =&amp;gt; johnsmith@domain.example, [3] =&amp;gt; johnsmith ) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:54--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:55--&amp;gt;&lt;br /&gt;
Notes:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:56--&amp;gt;&lt;br /&gt;
# The array indices are numeric starting from zero.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:57--&amp;gt;&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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadAssoc() ==== &amp;lt;!--T:58--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:59--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadAssoc()&amp;lt;/tt&amp;gt; returns an associated array from a single record in the table:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;loadAssoc();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:60--&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@domain.example, [username] =&amp;gt; johnsmith )&amp;lt;/pre&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:61--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;name&#039;] // e.g. $row[&#039;email&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:62--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadObject() ==== &amp;lt;!--T:63--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:64--&amp;gt;&lt;br /&gt;
loadObject returns a PHP object from a single record in the table:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:65--&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@domain.example, [username] =&amp;gt; johnsmith )&amp;lt;/pre&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:66--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$result-&amp;gt;index // e.g. $result-&amp;gt;email&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:67--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
===Single Column Results === &amp;lt;!--T:68--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:69--&amp;gt;&lt;br /&gt;
Each of these results functions will return a single column from the database.&amp;lt;/translate&amp;gt; &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;
! &amp;lt;translate&amp;gt;&amp;lt;!--T:70--&amp;gt;&lt;br /&gt;
id&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:71--&amp;gt;&lt;br /&gt;
name&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:72--&amp;gt;&lt;br /&gt;
email&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:73--&amp;gt;&lt;br /&gt;
username&amp;lt;/translate&amp;gt;&lt;br /&gt;
|- &lt;br /&gt;
| 1 || style=&amp;quot;background:yellow&amp;quot; | John Smith || &amp;lt;translate&amp;gt;&amp;lt;!--T:74--&amp;gt;&lt;br /&gt;
johnsmith@domain.example&amp;lt;/translate&amp;gt; || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || style=&amp;quot;background:yellow&amp;quot; | Magda Hellman || &amp;lt;translate&amp;gt;&amp;lt;!--T:75--&amp;gt;&lt;br /&gt;
magda_h@domain.example&amp;lt;/translate&amp;gt; || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || style=&amp;quot;background:yellow&amp;quot; | Yvonne de Gaulle || &amp;lt;translate&amp;gt;&amp;lt;!--T:76--&amp;gt;&lt;br /&gt;
ydg@domain.example&amp;lt;/translate&amp;gt; || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadColumn() ==== &amp;lt;!--T:77--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:78--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadColumn()&amp;lt;/tt&amp;gt; returns an indexed array from a single column in the table:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
$query-&amp;gt;select(&#039;name&#039;));&lt;br /&gt;
      -&amp;gt;from . . .&amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadColumn();&lt;br /&gt;
print_r($column);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:79--&amp;gt;&lt;br /&gt;
will give:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:80--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:81--&amp;gt;&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&lt;br /&gt;
# &amp;lt;tt&amp;gt;loadColumn()&amp;lt;/tt&amp;gt; is equivalent to loadColumn(0).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadColumn($index) ==== &amp;lt;!--T:82--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:83--&amp;gt;&lt;br /&gt;
loadColumn($index) returns an indexed array from a single column in the table:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
$query-&amp;gt;select(array(&#039;name&#039;, &#039;email&#039;, &#039;username&#039;));&lt;br /&gt;
      -&amp;gt;from . . .&amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadColumn(1);&lt;br /&gt;
print_r($column);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:84--&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; johnsmith@domain.example, [1] =&amp;gt; magda_h@domain.example, [2] =&amp;gt; ydg@domain.example )&amp;lt;/pre&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:85--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:86--&amp;gt;&lt;br /&gt;
loadColumn($index) allows you to iterate through a series of columns in the results&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;loadColumn($i);&lt;br /&gt;
  print_r($column);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:87--&amp;gt;&lt;br /&gt;
will give:&amp;lt;/translate&amp;gt;&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@domain.example, [1] =&amp;gt; magda_h@domain.example, [2] =&amp;gt; ydg@domain.example ),&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:88--&amp;gt;&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Multi-Row Results === &amp;lt;!--T:89--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:90--&amp;gt;&lt;br /&gt;
Each of these results functions will return multiple records from the database.&amp;lt;/translate&amp;gt; &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;
! &amp;lt;translate&amp;gt;&amp;lt;!--T:91--&amp;gt;&lt;br /&gt;
id&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:92--&amp;gt;&lt;br /&gt;
name&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:93--&amp;gt;&lt;br /&gt;
email&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:94--&amp;gt;&lt;br /&gt;
username&amp;lt;/translate&amp;gt;&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 1 || John Smith || johnsmith@domain.example || johnsmith&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadRowList() ==== &amp;lt;!--T:95--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:96--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadRowList()&amp;lt;/tt&amp;gt; returns an indexed array of indexed arrays from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:97--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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@domain.example, [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@domain.example, [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@domain.example, [3] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:98--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;index&#039;] // e.g. $row[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:99--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:100--&amp;gt;&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;==== loadAssocList() ==== &amp;lt;!--T:101--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:102--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadAssocList()&amp;lt;/tt&amp;gt; returns an indexed array of associated arrays from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:103--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&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@domain.example, [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@domain.example, [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@domain.example, [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:104--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;index&#039;] // e.g. $row[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:105--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;==== loadAssocList($key) ==== &amp;lt;!--T:106--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:107--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadAssocList(&#039;key&#039;)&amp;lt;/tt&amp;gt; returns an associated array - indexed on &#039;key&#039; - of associated arrays from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:108--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&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@domain.example, [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@domain.example, [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@domain.example, [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:109--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;key_value&#039;] // e.g. $row[&#039;johnsmith&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:110--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:111--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;==== loadAssocList($key, $column) ==== &amp;lt;!--T:112--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:113--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadAssocList(&#039;key&#039;, &#039;column&#039;)&amp;lt;/tt&amp;gt; returns an associative array, indexed on &#039;key&#039;, of values from the column named &#039;column&#039; returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;id&#039;, &#039;username&#039;);&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:114--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[1] =&amp;gt; John Smith, &lt;br /&gt;
[2] =&amp;gt; Magda Hellman, &lt;br /&gt;
[3] =&amp;gt; Yvonne de Gaulle,&lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:115--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;==== loadObjectList() ==== &amp;lt;!--T:116--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:117--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadObjectList()&amp;lt;/tt&amp;gt; returns an indexed array of PHP objects from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:118--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&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@domain.example, [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@domain.example, [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@domain.example, [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:119--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;index&#039;] // e.g. $row[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:120--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;==== loadObjectList($key) ==== &amp;lt;!--T:121--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:122--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadObjectList(&#039;key&#039;)&amp;lt;/tt&amp;gt; returns an associated array - indexed on &#039;key&#039; - of objects from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:123--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&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@domain.example, [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@domain.example, [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@domain.example, [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:124--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;key_value&#039;] // e.g. $row[&#039;johnsmith&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:125--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:126--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Miscellaneous Result Set Methods === &amp;lt;!--T:127--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== getNumRows() ==== &amp;lt;!--T:128--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:129--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;getNumRows()&amp;lt;/tt&amp;gt; will return the number of result rows found by the last SELECT or SHOW 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. To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or DELETE query, use getAffectedRows().&amp;lt;/translate&amp;gt;&lt;br /&gt;
 &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;execute();&lt;br /&gt;
$num_rows = $db-&amp;gt;getNumRows();&lt;br /&gt;
print_r($num_rows);&lt;br /&gt;
$result = $db-&amp;gt;loadRowList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:130--&amp;gt;&lt;br /&gt;
will return&amp;lt;/translate&amp;gt; &amp;lt;pre&amp;gt;3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:131--&amp;gt;&lt;br /&gt;
Note: getNumRows() is only valid for statements like SELECT or SHOW that return an actual result set. If you run getNumRows() after loadRowList() - or any other retrieval method - you will get a PHP Warning:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Warning: mysql_num_rows(): 80 is not a valid MySQL result resource &lt;br /&gt;
in libraries\joomla\database\database\mysql.php on line 344&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sample Module Code ==&lt;br /&gt;
&lt;br /&gt;
Below is the code for a simple Joomla module which you can install and run to demonstrate use of the JDatabase functionality, and which you can adapt to experiment with some of the concepts described above. If you are unsure about development and installing a Joomla module then following the tutorial at [[S:MyLanguage/J3.x:Creating a simple module/Introduction| Creating a simple module ]] will help.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important note: In any Joomla extensions which you develop that you should avoid accessing the core Joomla tables directly like this and should instead use the Joomla APIs if at all possible, because the database structures may change without warning.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In a folder mod_db_select create the following 2 files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;mod_db_select.xml&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;extension type=&amp;quot;module&amp;quot; version=&amp;quot;3.1&amp;quot; client=&amp;quot;site&amp;quot; method=&amp;quot;upgrade&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;Database select query demo&amp;lt;/name&amp;gt;&lt;br /&gt;
    &amp;lt;version&amp;gt;1.0.1&amp;lt;/version&amp;gt;&lt;br /&gt;
    &amp;lt;description&amp;gt;Code demonstrating use of Joomla Database class to perform SQL SELECT queries&amp;lt;/description&amp;gt;&lt;br /&gt;
    &amp;lt;files&amp;gt;&lt;br /&gt;
        &amp;lt;filename module=&amp;quot;mod_db_select&amp;quot;&amp;gt;mod_db_select.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
    &amp;lt;/files&amp;gt;&lt;br /&gt;
&amp;lt;/extension&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;mod_db_select.php&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die(&#039;Restricted Access&#039;);&lt;br /&gt;
&lt;br /&gt;
use Joomla\CMS\Factory;&lt;br /&gt;
&lt;br /&gt;
$db = Factory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$me = Factory::getUser();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;select($db-&amp;gt;quoteName(array(&#039;name&#039;, &#039;email&#039;)))&lt;br /&gt;
	-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__users&#039;))&lt;br /&gt;
	-&amp;gt;where($db-&amp;gt;quoteName(&#039;id&#039;) . &#039; != &#039; . $db-&amp;gt;quote($me-&amp;gt;id))&lt;br /&gt;
	-&amp;gt;order($db-&amp;gt;quoteName(&#039;name&#039;) . &#039; ASC&#039;);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
echo $db-&amp;gt;replacePrefix((string) $query);&lt;br /&gt;
&lt;br /&gt;
$results = $db-&amp;gt;loadAssocList();&lt;br /&gt;
&lt;br /&gt;
foreach ($results as $row) {&lt;br /&gt;
	echo &amp;quot;&amp;lt;p&amp;gt;&amp;quot; . $row[&#039;name&#039;] . &amp;quot;, &amp;quot; . $row[&#039;email&#039;] . &amp;quot;&amp;lt;br&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code above selects and outputs the username and email of the records in the Joomla &amp;lt;tt&amp;gt;users&amp;lt;/tt&amp;gt; table, apart from those of the currently logged-on user. The method &amp;lt;tt&amp;gt;Factory::getUser()&amp;lt;/tt&amp;gt; returns the &amp;lt;tt&amp;gt;user&amp;lt;/tt&amp;gt; object of the currently logged-on user, or if not logged on, then a blank &amp;lt;tt&amp;gt;user&amp;lt;/tt&amp;gt; object, whose &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt; field is set to zero. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;$db-&amp;gt;replacePrefix((string) $query)&amp;lt;/tt&amp;gt; expression returns the actual SQL statement, and outputting this can be useful in debugging. &lt;br /&gt;
&lt;br /&gt;
Zip up the mod_db_select directory to create &amp;lt;tt&amp;gt;mod_db_select.zip&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Within your Joomla administrator go to Install Extensions and via the Upload Package File tab select this zip file to install this sample log module.&lt;br /&gt;
&lt;br /&gt;
Make this module visible by editing it (click on it within the Modules page) then:&lt;br /&gt;
# making its status Published&lt;br /&gt;
# selecting a position on the page for it to be shown&lt;br /&gt;
# on the menu assignment tab specify the pages it should appear on&lt;br /&gt;
&lt;br /&gt;
When you visit a site web page then you should see the module in your selected position, and it should output the SQL SELECT statement and the sequence of name, email values from the Joomla users table. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== See also == &amp;lt;!--T:135--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
*[[S:MyLanguage/Inserting, Updating and Removing data using JDatabase|&amp;lt;translate&amp;gt;&amp;lt;!--T:136--&amp;gt; Inserting, Updating and Removing data using JDatabase&amp;lt;/translate&amp;gt;]]&lt;br /&gt;
*[[S:MyLanguage/Using the union methods in database queries|&amp;lt;translate&amp;gt;&amp;lt;!--T:137--&amp;gt; Using the union methods in database queries&amp;lt;/translate&amp;gt;]] &amp;lt;translate&amp;gt;&amp;lt;!--T:138--&amp;gt; (Joomla! 3.3+)&amp;lt;/translate&amp;gt;&lt;br /&gt;
*[https://api.joomla.org/cms-3/classes/JDatabaseQuery.html &amp;lt;translate&amp;gt;&amp;lt;!--T:139--&amp;gt; Joomla CMS 3.8 API&amp;lt;/translate&amp;gt;] &lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
[[Category:Database{{#translation:}}]]&lt;br /&gt;
[[Category:JFactory{{#translation:}}]]&lt;br /&gt;
[[Category:Extension development{{#translation:}}]]&lt;br /&gt;
[[Category:Development Recommended Reading{{#translation:}}]]&lt;br /&gt;
[[Category:Tutorials{{#translation:}}]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=783944</id>
		<title>Selecting data using JDatabase</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=783944"/>
		<updated>2021-02-25T11:29:26Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: note on empty results being null&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;&amp;lt;languages /&amp;gt;&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&amp;lt;noinclude&amp;gt;{{Joomla version|version=3.x}}{{Joomla version|version=2.5|status=eos}}&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
{{-}}&lt;br /&gt;
{{tip|&amp;lt;translate&amp;gt;&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
Note many examples online use &amp;lt;code&amp;gt;$db-&amp;gt;query()&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;$db-&amp;gt;execute()&amp;lt;/code&amp;gt;. This was the old method in Joomla 1.5 and 2.5 and will throw a deprecated notice in Joomla 3.0+.&amp;lt;/translate&amp;gt;|title=&amp;lt;translate&amp;gt;&amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
Version Note&amp;lt;/translate&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
This tutorial is split into two independent parts:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
* Inserting, updating and removing data from the database.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
* Selecting data from one or more tables and retrieving it in a variety of different forms&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
This section of the documentation looks at selecting data from a database table and retrieving it in a variety of formats. To see the other part [[S:MyLanguage/Inserting,_Updating_and_Removing_data_using_JDatabase|click here]]&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Introduction== &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
Joomla can use different kinds of SQL database systems and 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 you need just two 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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==The Query== &amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
Joomla&#039;s database querying changed with the introduction of Joomla 1.6. The recommended way of building database queries is through &amp;quot;query chaining&amp;quot; (although string queries are still supported).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source&#039;s query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer&#039;s source code.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code&amp;lt;/translate&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==Selecting Records from a Single Table== &amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
Below is an example of creating a database query using the &amp;lt;tt&amp;gt;JDatabaseQuery&amp;lt;/tt&amp;gt; class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)));&lt;br /&gt;
$query-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;));&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;custom.%&#039;));&lt;br /&gt;
$query-&amp;gt;order(&#039;ordering ASC&#039;);&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects (see later for more options on retrieving data).&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Here the &amp;lt;tt&amp;gt;quoteName()&amp;lt;/tt&amp;gt; function adds appropriate quotes around the column names to avoid conflicts with any database reserved word, now or in the future.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:19--&amp;gt;&lt;br /&gt;
The query can also be chained to simplify further:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;custom.%&#039;))&lt;br /&gt;
    -&amp;gt;order(&#039;ordering ASC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
Chaining method calls improves code readability and reduces code bloat as queries become longer and more complex.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
Grouping can be achieved simply too.  The following query would count the number of articles in each category.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array(&#039;catid&#039;, &#039;COUNT(*)&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;))&lt;br /&gt;
    -&amp;gt;group($db-&amp;gt;quoteName(&#039;catid&#039;));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
A limit can be set to a query using &amp;quot;setLimit&amp;quot;. For example in the following query, it would return up to 10 records.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;))&lt;br /&gt;
    -&amp;gt;setLimit(&#039;10&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Selecting Records from Multiple Tables== &amp;lt;!--T:23--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:24--&amp;gt;&lt;br /&gt;
Using the JDatabaseQuery&#039;s [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with &#039;a&#039;.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
// Note by putting &#039;a&#039; as a second parameter will generate `#__content` AS `a`&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;a%&#039;))&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects (see later for more options on retrieving data).&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for joins:&amp;lt;/translate&amp;gt;&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_innerJoin innerJoin()]&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_leftJoin leftJoin()]&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_rightJoin rightJoin()] &lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_outerJoin outerJoin()]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:26--&amp;gt;&lt;br /&gt;
We can use multiple joins to query across more than two tables:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;, &#039;c.*&#039;, &#039;d.*&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;LEFT&#039;, $db-&amp;gt;quoteName(&#039;#__user_profiles&#039;, &#039;c&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;c.user_id&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;RIGHT&#039;, $db-&amp;gt;quoteName(&#039;#__categories&#039;, &#039;d&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.catid&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;d.id&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;a%&#039;))&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:27--&amp;gt;&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:28--&amp;gt;&lt;br /&gt;
In some cases, you will also need to use the AS clause when selecting items to avoid column name conflicts. In this case, multiple select statements can be chained in conjunction with using the second parameter of $db-&amp;gt;quoteName.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(&#039;a.*&#039;)&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(&#039;b.username&#039;, &#039;username&#039;))&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(&#039;b.name&#039;, &#039;name&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;a%&#039;))&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:29--&amp;gt;&lt;br /&gt;
A second array can also be used as the second parameter of the select statement to populate the values of the AS clause. Remember to include nulls in the second array to correspond to columns in the first array that you don&#039;t want to use the AS clause for:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array(&#039;a.*&#039;))&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;b.username&#039;, &#039;b.name&#039;), array(&#039;username&#039;, &#039;name&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;a%&#039;))&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==Using OR in queries== &amp;lt;!--T:140--&amp;gt; &amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:141--&amp;gt;&lt;br /&gt;
When using multiple WHERE clauses in your query, they will be treated as an AND.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:142--&amp;gt;&lt;br /&gt;
So, for example, the query below will return results where the &#039;name&#039; field AND the &#039;state&#039; field match.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;COUNT(*)&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($value)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;state&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($state));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:143--&amp;gt;&lt;br /&gt;
To use a WHERE clause as an OR, the query can be written like this&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;COUNT(*)&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($name_one), &#039;OR&#039;)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($name_two));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:144--&amp;gt;&lt;br /&gt;
it can also be written like this&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;COUNT(*)&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($name_one)&lt;br /&gt;
    -&amp;gt;orWhere($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($name_two));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==Query Results == &amp;lt;!--T:30--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:31--&amp;gt;&lt;br /&gt;
The database class contains many methods for working with a query&#039;s result set.&lt;br /&gt;
&lt;br /&gt;
If there are no matches to the quesry, the result will be null.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Single Value Result === &amp;lt;!--T:32--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadResult() ==== &amp;lt;!--T:33--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:34--&amp;gt;&lt;br /&gt;
Use &#039;&#039;&#039;loadResult()&#039;&#039;&#039; when you expect just a single value back from your database query.&amp;lt;/translate&amp;gt; &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;
! &amp;lt;translate&amp;gt;&amp;lt;!--T:35--&amp;gt;&lt;br /&gt;
id&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:36--&amp;gt;&lt;br /&gt;
name&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:37--&amp;gt;&lt;br /&gt;
email&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:38--&amp;gt;&lt;br /&gt;
username&amp;lt;/translate&amp;gt;&lt;br /&gt;
|- &lt;br /&gt;
| 1 || style=&amp;quot;background:yellow&amp;quot; | John Smith || &amp;lt;translate&amp;gt;&amp;lt;!--T:39--&amp;gt;&lt;br /&gt;
johnsmith@domain.example&amp;lt;/translate&amp;gt; || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || &amp;lt;translate&amp;gt;&amp;lt;!--T:40--&amp;gt;&lt;br /&gt;
magda_h@domain.example&amp;lt;/translate&amp;gt; || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || &amp;lt;translate&amp;gt;&amp;lt;!--T:41--&amp;gt;&lt;br /&gt;
ydg@domain.example&amp;lt;/translate&amp;gt; || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:42--&amp;gt;&lt;br /&gt;
This is often the result of a &#039;count&#039; query to get a number of records:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;COUNT(*)&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($value));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:134--&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).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;field_name&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;some_name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($some_value));&lt;br /&gt;
&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;
&amp;lt;translate&amp;gt;&lt;br /&gt;
===Single Row Results === &amp;lt;!--T:43--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:44--&amp;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.&amp;lt;/translate&amp;gt;&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;
! &amp;lt;translate&amp;gt;&amp;lt;!--T:45--&amp;gt;&lt;br /&gt;
id&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:46--&amp;gt;&lt;br /&gt;
name&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:47--&amp;gt;&lt;br /&gt;
email&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:48--&amp;gt;&lt;br /&gt;
username&amp;lt;/translate&amp;gt;&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 1 || John Smith || &amp;lt;translate&amp;gt;&amp;lt;!--T:49--&amp;gt;&lt;br /&gt;
johnsmith@domain.example&amp;lt;/translate&amp;gt; || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || &amp;lt;translate&amp;gt;&amp;lt;!--T:50--&amp;gt;&lt;br /&gt;
magda_h@domain.example&amp;lt;/translate&amp;gt; || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || &amp;lt;translate&amp;gt;&amp;lt;!--T:51--&amp;gt;&lt;br /&gt;
ydg@domain.example&amp;lt;/translate&amp;gt; || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadRow() ==== &amp;lt;!--T:52--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:53--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadRow()&amp;lt;/tt&amp;gt; returns an indexed array from a single record in the table:&amp;lt;/translate&amp;gt; &lt;br /&gt;
&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:133--&amp;gt;&lt;br /&gt;
will give:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; 1, [1] =&amp;gt; John Smith, [2] =&amp;gt; johnsmith@domain.example, [3] =&amp;gt; johnsmith ) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:54--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:55--&amp;gt;&lt;br /&gt;
Notes:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:56--&amp;gt;&lt;br /&gt;
# The array indices are numeric starting from zero.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:57--&amp;gt;&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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadAssoc() ==== &amp;lt;!--T:58--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:59--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadAssoc()&amp;lt;/tt&amp;gt; returns an associated array from a single record in the table:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;loadAssoc();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:60--&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@domain.example, [username] =&amp;gt; johnsmith )&amp;lt;/pre&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:61--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;name&#039;] // e.g. $row[&#039;email&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:62--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadObject() ==== &amp;lt;!--T:63--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:64--&amp;gt;&lt;br /&gt;
loadObject returns a PHP object from a single record in the table:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:65--&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@domain.example, [username] =&amp;gt; johnsmith )&amp;lt;/pre&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:66--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$result-&amp;gt;index // e.g. $result-&amp;gt;email&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:67--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
===Single Column Results === &amp;lt;!--T:68--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:69--&amp;gt;&lt;br /&gt;
Each of these results functions will return a single column from the database.&amp;lt;/translate&amp;gt; &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;
! &amp;lt;translate&amp;gt;&amp;lt;!--T:70--&amp;gt;&lt;br /&gt;
id&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:71--&amp;gt;&lt;br /&gt;
name&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:72--&amp;gt;&lt;br /&gt;
email&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:73--&amp;gt;&lt;br /&gt;
username&amp;lt;/translate&amp;gt;&lt;br /&gt;
|- &lt;br /&gt;
| 1 || style=&amp;quot;background:yellow&amp;quot; | John Smith || &amp;lt;translate&amp;gt;&amp;lt;!--T:74--&amp;gt;&lt;br /&gt;
johnsmith@domain.example&amp;lt;/translate&amp;gt; || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || style=&amp;quot;background:yellow&amp;quot; | Magda Hellman || &amp;lt;translate&amp;gt;&amp;lt;!--T:75--&amp;gt;&lt;br /&gt;
magda_h@domain.example&amp;lt;/translate&amp;gt; || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || style=&amp;quot;background:yellow&amp;quot; | Yvonne de Gaulle || &amp;lt;translate&amp;gt;&amp;lt;!--T:76--&amp;gt;&lt;br /&gt;
ydg@domain.example&amp;lt;/translate&amp;gt; || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadColumn() ==== &amp;lt;!--T:77--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:78--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadColumn()&amp;lt;/tt&amp;gt; returns an indexed array from a single column in the table:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
$query-&amp;gt;select(&#039;name&#039;));&lt;br /&gt;
      -&amp;gt;from . . .&amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadColumn();&lt;br /&gt;
print_r($column);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:79--&amp;gt;&lt;br /&gt;
will give:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:80--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:81--&amp;gt;&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&lt;br /&gt;
# &amp;lt;tt&amp;gt;loadColumn()&amp;lt;/tt&amp;gt; is equivalent to loadColumn(0).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadColumn($index) ==== &amp;lt;!--T:82--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:83--&amp;gt;&lt;br /&gt;
loadColumn($index) returns an indexed array from a single column in the table:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
$query-&amp;gt;select(array(&#039;name&#039;, &#039;email&#039;, &#039;username&#039;));&lt;br /&gt;
      -&amp;gt;from . . .&amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadColumn(1);&lt;br /&gt;
print_r($column);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:84--&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; johnsmith@domain.example, [1] =&amp;gt; magda_h@domain.example, [2] =&amp;gt; ydg@domain.example )&amp;lt;/pre&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:85--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:86--&amp;gt;&lt;br /&gt;
loadColumn($index) allows you to iterate through a series of columns in the results&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;loadColumn($i);&lt;br /&gt;
  print_r($column);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:87--&amp;gt;&lt;br /&gt;
will give:&amp;lt;/translate&amp;gt;&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@domain.example, [1] =&amp;gt; magda_h@domain.example, [2] =&amp;gt; ydg@domain.example ),&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:88--&amp;gt;&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Multi-Row Results === &amp;lt;!--T:89--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:90--&amp;gt;&lt;br /&gt;
Each of these results functions will return multiple records from the database.&amp;lt;/translate&amp;gt; &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;
! &amp;lt;translate&amp;gt;&amp;lt;!--T:91--&amp;gt;&lt;br /&gt;
id&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:92--&amp;gt;&lt;br /&gt;
name&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:93--&amp;gt;&lt;br /&gt;
email&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:94--&amp;gt;&lt;br /&gt;
username&amp;lt;/translate&amp;gt;&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 1 || John Smith || johnsmith@domain.example || johnsmith&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadRowList() ==== &amp;lt;!--T:95--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:96--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadRowList()&amp;lt;/tt&amp;gt; returns an indexed array of indexed arrays from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:97--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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@domain.example, [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@domain.example, [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@domain.example, [3] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:98--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;index&#039;] // e.g. $row[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:99--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:100--&amp;gt;&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;==== loadAssocList() ==== &amp;lt;!--T:101--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:102--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadAssocList()&amp;lt;/tt&amp;gt; returns an indexed array of associated arrays from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:103--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&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@domain.example, [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@domain.example, [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@domain.example, [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:104--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;index&#039;] // e.g. $row[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:105--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;==== loadAssocList($key) ==== &amp;lt;!--T:106--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:107--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadAssocList(&#039;key&#039;)&amp;lt;/tt&amp;gt; returns an associated array - indexed on &#039;key&#039; - of associated arrays from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:108--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&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@domain.example, [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@domain.example, [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@domain.example, [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:109--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;key_value&#039;] // e.g. $row[&#039;johnsmith&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:110--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:111--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;==== loadAssocList($key, $column) ==== &amp;lt;!--T:112--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:113--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadAssocList(&#039;key&#039;, &#039;column&#039;)&amp;lt;/tt&amp;gt; returns an associative array, indexed on &#039;key&#039;, of values from the column named &#039;column&#039; returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;id&#039;, &#039;username&#039;);&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:114--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[1] =&amp;gt; John Smith, &lt;br /&gt;
[2] =&amp;gt; Magda Hellman, &lt;br /&gt;
[3] =&amp;gt; Yvonne de Gaulle,&lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:115--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;==== loadObjectList() ==== &amp;lt;!--T:116--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:117--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadObjectList()&amp;lt;/tt&amp;gt; returns an indexed array of PHP objects from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:118--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&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@domain.example, [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@domain.example, [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@domain.example, [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:119--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;index&#039;] // e.g. $row[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:120--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;==== loadObjectList($key) ==== &amp;lt;!--T:121--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:122--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadObjectList(&#039;key&#039;)&amp;lt;/tt&amp;gt; returns an associated array - indexed on &#039;key&#039; - of objects from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:123--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&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@domain.example, [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@domain.example, [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@domain.example, [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:124--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;key_value&#039;] // e.g. $row[&#039;johnsmith&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:125--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:126--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Miscellaneous Result Set Methods === &amp;lt;!--T:127--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== getNumRows() ==== &amp;lt;!--T:128--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:129--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;getNumRows()&amp;lt;/tt&amp;gt; will return the number of result rows found by the last SELECT or SHOW 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. To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or DELETE query, use getAffectedRows().&amp;lt;/translate&amp;gt;&lt;br /&gt;
 &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;execute();&lt;br /&gt;
$num_rows = $db-&amp;gt;getNumRows();&lt;br /&gt;
print_r($num_rows);&lt;br /&gt;
$result = $db-&amp;gt;loadRowList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:130--&amp;gt;&lt;br /&gt;
will return&amp;lt;/translate&amp;gt; &amp;lt;pre&amp;gt;3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:131--&amp;gt;&lt;br /&gt;
Note: getNumRows() is only valid for statements like SELECT or SHOW that return an actual result set. If you run getNumRows() after loadRowList() - or any other retrieval method - you will get a PHP Warning:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Warning: mysql_num_rows(): 80 is not a valid MySQL result resource &lt;br /&gt;
in libraries\joomla\database\database\mysql.php on line 344&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sample Module Code ==&lt;br /&gt;
&lt;br /&gt;
Below is the code for a simple Joomla module which you can install and run to demonstrate use of the JDatabase functionality, and which you can adapt to experiment with some of the concepts described above. If you are unsure about development and installing a Joomla module then following the tutorial at [[S:MyLanguage/J3.x:Creating a simple module/Introduction| Creating a simple module ]] will help.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important note: In any Joomla extensions which you develop that you should avoid accessing the core Joomla tables directly like this and should instead use the Joomla APIs if at all possible, because the database structures may change without warning.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In a folder mod_db_select create the following 2 files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;mod_db_select.xml&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;extension type=&amp;quot;module&amp;quot; version=&amp;quot;3.1&amp;quot; client=&amp;quot;site&amp;quot; method=&amp;quot;upgrade&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;Database select query demo&amp;lt;/name&amp;gt;&lt;br /&gt;
    &amp;lt;version&amp;gt;1.0.1&amp;lt;/version&amp;gt;&lt;br /&gt;
    &amp;lt;description&amp;gt;Code demonstrating use of Joomla Database class to perform SQL SELECT queries&amp;lt;/description&amp;gt;&lt;br /&gt;
    &amp;lt;files&amp;gt;&lt;br /&gt;
        &amp;lt;filename module=&amp;quot;mod_db_select&amp;quot;&amp;gt;mod_db_select.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
    &amp;lt;/files&amp;gt;&lt;br /&gt;
&amp;lt;/extension&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;mod_db_select.php&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die(&#039;Restricted Access&#039;);&lt;br /&gt;
&lt;br /&gt;
use Joomla\CMS\Factory;&lt;br /&gt;
&lt;br /&gt;
$db = Factory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$me = Factory::getUser();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;select($db-&amp;gt;quoteName(array(&#039;name&#039;, &#039;email&#039;)))&lt;br /&gt;
	-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__users&#039;))&lt;br /&gt;
	-&amp;gt;where($db-&amp;gt;quoteName(&#039;id&#039;) . &#039; != &#039; . $db-&amp;gt;quote($me-&amp;gt;id))&lt;br /&gt;
	-&amp;gt;order($db-&amp;gt;quoteName(&#039;name&#039;) . &#039; ASC&#039;);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
echo $db-&amp;gt;replacePrefix((string) $query);&lt;br /&gt;
&lt;br /&gt;
$results = $db-&amp;gt;loadAssocList();&lt;br /&gt;
&lt;br /&gt;
foreach ($results as $row) {&lt;br /&gt;
	echo &amp;quot;&amp;lt;p&amp;gt;&amp;quot; . $row[&#039;name&#039;] . &amp;quot;, &amp;quot; . $row[&#039;email&#039;] . &amp;quot;&amp;lt;br&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code above selects and outputs the username and email of the records in the Joomla &amp;lt;tt&amp;gt;users&amp;lt;/tt&amp;gt; table, apart from those of the currently logged-on user. The method &amp;lt;tt&amp;gt;Factory::getUser()&amp;lt;/tt&amp;gt; returns the &amp;lt;tt&amp;gt;user&amp;lt;/tt&amp;gt; object of the currently logged-on user, or if not logged on, then a blank &amp;lt;tt&amp;gt;user&amp;lt;/tt&amp;gt; object, whose &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt; field is set to zero. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;$db-&amp;gt;replacePrefix((string) $query)&amp;lt;/tt&amp;gt; expression returns the actual SQL statement, and outputting this can be useful in debugging. &lt;br /&gt;
&lt;br /&gt;
Zip up the mod_db_select directory to create &amp;lt;tt&amp;gt;mod_db_select.zip&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Within your Joomla administrator go to Install Extensions and via the Upload Package File tab select this zip file to install this sample log module.&lt;br /&gt;
&lt;br /&gt;
Make this module visible by editing it (click on it within the Modules page) then:&lt;br /&gt;
# making its status Published&lt;br /&gt;
# selecting a position on the page for it to be shown&lt;br /&gt;
# on the menu assignment tab specify the pages it should appear on&lt;br /&gt;
&lt;br /&gt;
When you visit a site web page then you should see the module in your selected position, and it should output the SQL SELECT statement and the sequence of name, email values from the Joomla users table. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== See also == &amp;lt;!--T:135--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
*[[S:MyLanguage/Inserting, Updating and Removing data using JDatabase|&amp;lt;translate&amp;gt;&amp;lt;!--T:136--&amp;gt; Inserting, Updating and Removing data using JDatabase&amp;lt;/translate&amp;gt;]]&lt;br /&gt;
*[[S:MyLanguage/Using the union methods in database queries|&amp;lt;translate&amp;gt;&amp;lt;!--T:137--&amp;gt; Using the union methods in database queries&amp;lt;/translate&amp;gt;]] &amp;lt;translate&amp;gt;&amp;lt;!--T:138--&amp;gt; (Joomla! 3.3+)&amp;lt;/translate&amp;gt;&lt;br /&gt;
*[https://api.joomla.org/cms-3/classes/JDatabaseQuery.html &amp;lt;translate&amp;gt;&amp;lt;!--T:139--&amp;gt; Joomla CMS 3.8 API&amp;lt;/translate&amp;gt;] &lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
[[Category:Database{{#translation:}}]]&lt;br /&gt;
[[Category:JFactory{{#translation:}}]]&lt;br /&gt;
[[Category:Extension development{{#translation:}}]]&lt;br /&gt;
[[Category:Development Recommended Reading{{#translation:}}]]&lt;br /&gt;
[[Category:Tutorials{{#translation:}}]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Make_changes_to_an_article_automatically_using_a_plugin&amp;diff=719013</id>
		<title>Make changes to an article automatically using a plugin</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Make_changes_to_an_article_automatically_using_a_plugin&amp;diff=719013"/>
		<updated>2020-09-01T14:25:07Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
Plugins are the simplest extensions to write. A simple plugin requires only two files. Yet plugins can be extremely handy.&lt;br /&gt;
&lt;br /&gt;
One common case for using plugins is doing some customized processing every time an article is saved. For example:&lt;br /&gt;
* Change the published state of an article.&lt;br /&gt;
* Add standard text to articles.&lt;br /&gt;
* Set the Section or Category for an article.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see how you can use a simple plugin to do these types of tasks.&lt;br /&gt;
&lt;br /&gt;
==First Plugin==&lt;br /&gt;
A simple plugin has two files. One is an XML file that tells Joomla! how to install the plugin. The other is the actual plugin PHP code.&lt;br /&gt;
&lt;br /&gt;
To make it as easy as possible for people to write plugins, Joomla! includes example plugins in every installation. In our example, we are writing a &amp;quot;content&amp;quot; plugin, since we are working with articles. So the two example files we can use as guidelines are &amp;lt;tt&amp;gt;plugins/content/example.xml&amp;lt;/tt&amp;gt; amd &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The XML file for our example is called &amp;lt;tt&amp;gt;modifyarticle.xml&amp;lt;/tt&amp;gt;. We just copied  the file &amp;lt;tt&amp;gt;plugins/content/example.xml&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;modifyarticle.xml&amp;lt;/tt&amp;gt; and put it in a new folder outside of the Joomla! installation. (&#039;&#039;We will use the Joomla! install program later on to add this to our Joomla! system. So for now we want to keep this separate from Joomla!.&#039;&#039;) Then we edited it as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;install version=&amp;quot;1.5&amp;quot; type=&amp;quot;plugin&amp;quot; group=&amp;quot;content&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;Modify Edited Articles&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;creationDate&amp;gt;January 2009&amp;lt;/creationDate&amp;gt;&lt;br /&gt;
&amp;lt;author&amp;gt;Joomla Doc Team&amp;lt;/author&amp;gt;&lt;br /&gt;
&amp;lt;authorEmail&amp;gt;myemail@myemail.com&amp;lt;/authorEmail&amp;gt;&lt;br /&gt;
&amp;lt;authorUrl&amp;gt;http://joomlacode.org&amp;lt;/authorUrl&amp;gt;&lt;br /&gt;
&amp;lt;copyright&amp;gt;Copyright (c) 2009&amp;lt;/copyright&amp;gt;&lt;br /&gt;
&amp;lt;license&amp;gt;GPL&amp;lt;/license&amp;gt;&lt;br /&gt;
&amp;lt;version&amp;gt;1.0.0&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;lt;description&amp;gt;Example plugin for Joomla! wiki.&amp;lt;/description&amp;gt;&lt;br /&gt;
&amp;lt;files&amp;gt;&lt;br /&gt;
   &amp;lt;filename plugin=&amp;quot;modifyarticle&amp;quot;&amp;gt;modifyarticle.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
&amp;lt;/files&amp;gt;&lt;br /&gt;
&amp;lt;/install&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Next, we copy the file &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;modifyarticle.php&amp;lt;/tt&amp;gt; and put it in the same folder outside of the Joomla! installation. Then we edit this file so it reads as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
/**&lt;br /&gt;
 * @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.&lt;br /&gt;
 * @license		GNU/GPL, see LICENSE.php&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
// Check to ensure this file is included in Joomla!&lt;br /&gt;
defined( &#039;_JEXEC&#039; ) or die( &#039;Restricted access&#039; );&lt;br /&gt;
&lt;br /&gt;
jimport( &#039;joomla.plugin.plugin&#039; );&lt;br /&gt;
&lt;br /&gt;
class plgContentModifyArticle extends JPlugin&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Example before save content method&lt;br /&gt;
	 *&lt;br /&gt;
	 * Method is called right before content is saved into the database.&lt;br /&gt;
	 * Article object is passed by reference, so any changes will be saved!&lt;br /&gt;
	 * NOTE:  Returning false will abort the save with an error.&lt;br /&gt;
	 * 	You can set the error by calling $article-&amp;gt;setError($message)&lt;br /&gt;
	 *&lt;br /&gt;
	 * @param 	object		A JTableContent object&lt;br /&gt;
	 * @param 	bool		If the content is just about to be created&lt;br /&gt;
	 * @return	bool		If false, abort the save&lt;br /&gt;
	 */&lt;br /&gt;
	function onContentBeforeSave( $context, &amp;amp;$article, $isNew )&lt;br /&gt;
	{&lt;br /&gt;
		$user =&amp;amp; JFactory::getUser(); // get the user&lt;br /&gt;
		if ($user-&amp;gt;usertype == &#039;Author&#039;) { // unpublish if user is &amp;quot;Author&amp;quot;&lt;br /&gt;
			$article-&amp;gt;state = 0; // from dev 11:59&lt;br /&gt;
		}&lt;br /&gt;
		return true;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Notice that the &amp;lt;tt&amp;gt;example.php&amp;lt;/tt&amp;gt; file has six methods plus the constructor. These document the six possible events that you can use for plugins. In our example, we want to modify the article just before it is saved to the database. So we call our method (or function) &amp;quot;onContentBeforeSave&amp;quot;. This method name must be exactly as shown. The name is what tells Joomla! when to run our plugin.&lt;br /&gt;
&lt;br /&gt;
In standard Joomla!, when a user in the &amp;quot;Author&amp;quot; group first submits a new article, it is set to &amp;quot;Unpublished&amp;quot;. However, once the article has been published, this user can edit the article and it stays published. In our example, we want to change this so that, each time an article is edited by a user in the &amp;quot;Author&amp;quot; group, it gets changed back to &amp;quot;Unpublished&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
The code above does that. First, we get the user. Then, if the user is in the &amp;quot;Author&amp;quot; group, we change the article&#039;s &amp;quot;state&amp;quot; to zero, meaning &amp;quot;Unpublished&amp;quot;. Notice that the method has &amp;lt;tt&amp;gt;$article&amp;lt;/tt&amp;gt; as a parameter, so its fields and methods are all available to us.&lt;br /&gt;
&lt;br /&gt;
==Install the Plugin==&lt;br /&gt;
Once we have the plugin coded, we need to create a zip archive so we can install it in our Joomla! site. Here are the steps:&lt;br /&gt;
* Use any Zip or Gzip program to make a Zip or Gzip archive of the two files created above.&lt;br /&gt;
* In the back end of your Joomla! site, navigate to Extensions &amp;amp;rarr; Install / Uninstall.&lt;br /&gt;
* Press Browse and find your zip archive file.&lt;br /&gt;
* Press Upload File and Install. You should get a message indicating that the extension was installed successfully.&lt;br /&gt;
* Finally, navigate to Extensions &amp;amp;rarr; Plugin Manager, find the new plugin (called &amp;quot;Modify Edited Articles&amp;quot; based on the name in the XML file), and enable it.&lt;br /&gt;
At this point, you should be able to test that it is working as expected.&lt;br /&gt;
&lt;br /&gt;
==Add Standard Text==&lt;br /&gt;
Once we have the basic framework, changing the plugin to do other things is simple. For example, say we want to add standard text to any article submitted by a user in the &amp;quot;Author&amp;quot; group. Here is the code for the &amp;quot;onBeforeContentSave()&amp;quot; method:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
	function onContentBeforeSave( $context, &amp;amp;$article, $isNew )&lt;br /&gt;
	{&lt;br /&gt;
		$newText = &#039;&amp;lt;p&amp;gt;This is my new text to add to the article.&amp;lt;/p&amp;gt;&#039;;&lt;br /&gt;
		$user =&amp;amp; JFactory::getUser(); // get the user&lt;br /&gt;
		if ($user-&amp;gt;usertype == &#039;Author&#039;) { &lt;br /&gt;
			if ($article-&amp;gt;fulltext) {&lt;br /&gt;
				if (strpos($article-&amp;gt;fulltext, $newText) == 0) {&lt;br /&gt;
					$article-&amp;gt;fulltext .= $newText;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
			else {&lt;br /&gt;
				if (strpos($article-&amp;gt;introtext, $newText) == 0) {&lt;br /&gt;
					$article-&amp;gt;introtext .= $newText;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		return true;&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In this code, we have some standard text we put in the &amp;lt;tt&amp;gt;$newText&amp;lt;/tt&amp;gt; variable. Then we deal with a complication of the &amp;lt;tt&amp;gt;$article&amp;lt;/tt&amp;gt; object. Joomla! articles can have an optional &amp;quot;Read more...&amp;quot; break. If they don&#039;t have one, the entire text of the article is in the &amp;lt;tt&amp;gt;introtext&amp;lt;/tt&amp;gt; field. If there is a &amp;quot;Read more...&amp;quot; break, then the part of the article after the break is in the &amp;lt;tt&amp;gt;fulltext&amp;lt;/tt&amp;gt; field. &lt;br /&gt;
&lt;br /&gt;
So, in the code, we have to handle both cases. If there is something in &amp;lt;tt&amp;gt;fulltext&amp;lt;/tt&amp;gt;, then we add the standard text there. Otherwise, we add it to &amp;lt;tt&amp;gt;introtext&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
There is one other complication. We don&#039;t want to add the standard text if it already there. Otherwise, we would keep adding more copies of it each time the article is edited. So we test to see if it already part of the article&#039;s text and we only add it if it isn&#039;t already there.&lt;br /&gt;
&lt;br /&gt;
Notice that the second parameter of this method is &amp;lt;tt&amp;gt;$isNew&amp;lt;/tt&amp;gt;. This is a boolean that is &amp;lt;tt&amp;gt;true&amp;lt;/tt&amp;gt; if this is a new article. So we could test for that if we only wanted to add the text for new article submissions.&lt;br /&gt;
&lt;br /&gt;
==Set the Section or Category==&lt;br /&gt;
Setting the Section or Category ID of an article is very easy. For example, in the Sample Website, this code&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
   $article-&amp;gt;sectionid = &#039;4&#039;;&lt;br /&gt;
   $article-&amp;gt;catid = &#039;25&#039;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
would change the article&#039;s Section to &amp;quot;About Joomla!&amp;quot; and Category to &amp;quot;The Project&amp;quot;. Note that you need to use the &amp;quot;id&amp;quot; fields for the Section and Category. In this example, you also might want to remove these fields from the front-end form (by using a [[How_to_override_the_output_from_the_Joomla!_core|template override]])&lt;br /&gt;
&lt;br /&gt;
==Other Things We Can Do==&lt;br /&gt;
It is useful to understand that any of the article&#039;s fields are available here. Below is a partial list:&lt;br /&gt;
* title: article&#039;s title&lt;br /&gt;
* alias: article&#039;s alias&lt;br /&gt;
* state: 0 for unpublished, 1 for published, -1 for archived&lt;br /&gt;
* created: date created&lt;br /&gt;
* created_by: user id of author&lt;br /&gt;
* created_by_alias: author alias field&lt;br /&gt;
* modified: date last modified&lt;br /&gt;
* modified_by: user id of last author to modify&lt;br /&gt;
* metakey: Metadata Information / Keywords&lt;br /&gt;
* metadesc: Metadata Information / Description&lt;br /&gt;
* access: 0 for public, 1 for registered, 2 for special&lt;br /&gt;
&lt;br /&gt;
Also, there are other built-in events we can use for plugins, see [https://docs.joomla.org/Plugin/Events/Content Plugin Events Content docs] for more info. These are documented in the &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt; file. In addition, there are other plugin types. See the [[Developers#Plugins|plugins section of the Wiki]] for more information. &lt;br /&gt;
&lt;br /&gt;
[[Category:Tips and tricks]]&lt;br /&gt;
[[Category:Tips and tricks 1.5]]&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Make_changes_to_an_article_automatically_using_a_plugin&amp;diff=719012</id>
		<title>Make changes to an article automatically using a plugin</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Make_changes_to_an_article_automatically_using_a_plugin&amp;diff=719012"/>
		<updated>2020-09-01T14:23:42Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
Plugins are the simplest extensions to write. A simple plugin requires only two files. Yet plugins can be extremely handy.&lt;br /&gt;
&lt;br /&gt;
One common case for using plugins is doing some customized processing every time an article is saved. For example:&lt;br /&gt;
* Change the published state of an article.&lt;br /&gt;
* Add standard text to articles.&lt;br /&gt;
* Set the Section or Category for an article.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see how you can use a simple plugin to do these types of tasks.&lt;br /&gt;
&lt;br /&gt;
==First Plugin==&lt;br /&gt;
A simple plugin has two files. One is an XML file that tells Joomla! how to install the plugin. The other is the actual plugin PHP code.&lt;br /&gt;
&lt;br /&gt;
To make it as easy as possible for people to write plugins, Joomla! includes example plugins in every installation. In our example, we are writing a &amp;quot;content&amp;quot; plugin, since we are working with articles. So the two example files we can use as guidelines are &amp;lt;tt&amp;gt;plugins/content/example.xml&amp;lt;/tt&amp;gt; amd &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The XML file for our example is called &amp;lt;tt&amp;gt;modifyarticle.xml&amp;lt;/tt&amp;gt;. We just copied  the file &amp;lt;tt&amp;gt;plugins/content/example.xml&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;modifyarticle.xml&amp;lt;/tt&amp;gt; and put it in a new folder outside of the Joomla! installation. (&#039;&#039;We will use the Joomla! install program later on to add this to our Joomla! system. So for now we want to keep this separate from Joomla!.&#039;&#039;) Then we edited it as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;install version=&amp;quot;1.5&amp;quot; type=&amp;quot;plugin&amp;quot; group=&amp;quot;content&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;Modify Edited Articles&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;creationDate&amp;gt;January 2009&amp;lt;/creationDate&amp;gt;&lt;br /&gt;
&amp;lt;author&amp;gt;Joomla Doc Team&amp;lt;/author&amp;gt;&lt;br /&gt;
&amp;lt;authorEmail&amp;gt;myemail@myemail.com&amp;lt;/authorEmail&amp;gt;&lt;br /&gt;
&amp;lt;authorUrl&amp;gt;http://joomlacode.org&amp;lt;/authorUrl&amp;gt;&lt;br /&gt;
&amp;lt;copyright&amp;gt;Copyright (c) 2009&amp;lt;/copyright&amp;gt;&lt;br /&gt;
&amp;lt;license&amp;gt;GPL&amp;lt;/license&amp;gt;&lt;br /&gt;
&amp;lt;version&amp;gt;1.0.0&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;lt;description&amp;gt;Example plugin for Joomla! wiki.&amp;lt;/description&amp;gt;&lt;br /&gt;
&amp;lt;files&amp;gt;&lt;br /&gt;
   &amp;lt;filename plugin=&amp;quot;modifyarticle&amp;quot;&amp;gt;modifyarticle.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
&amp;lt;/files&amp;gt;&lt;br /&gt;
&amp;lt;/install&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Next, we copy the file &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;modifyarticle.php&amp;lt;/tt&amp;gt; and put it in the same folder outside of the Joomla! installation. Then we edit this file so it reads as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
/**&lt;br /&gt;
 * @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.&lt;br /&gt;
 * @license		GNU/GPL, see LICENSE.php&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
// Check to ensure this file is included in Joomla!&lt;br /&gt;
defined( &#039;_JEXEC&#039; ) or die( &#039;Restricted access&#039; );&lt;br /&gt;
&lt;br /&gt;
jimport( &#039;joomla.plugin.plugin&#039; );&lt;br /&gt;
&lt;br /&gt;
class plgContentModifyArticle extends JPlugin&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Example before save content method&lt;br /&gt;
	 *&lt;br /&gt;
	 * Method is called right before content is saved into the database.&lt;br /&gt;
	 * Article object is passed by reference, so any changes will be saved!&lt;br /&gt;
	 * NOTE:  Returning false will abort the save with an error.&lt;br /&gt;
	 * 	You can set the error by calling $article-&amp;gt;setError($message)&lt;br /&gt;
	 *&lt;br /&gt;
	 * @param 	object		A JTableContent object&lt;br /&gt;
	 * @param 	bool		If the content is just about to be created&lt;br /&gt;
	 * @return	bool		If false, abort the save&lt;br /&gt;
	 */&lt;br /&gt;
	function onContentBeforeSave( $context, &amp;amp;$article, $isNew )&lt;br /&gt;
	{&lt;br /&gt;
		$user =&amp;amp; JFactory::getUser(); // get the user&lt;br /&gt;
		if ($user-&amp;gt;usertype == &#039;Author&#039;) { // unpublish if user is &amp;quot;Author&amp;quot;&lt;br /&gt;
			$article-&amp;gt;state = 0; // from dev 11:59&lt;br /&gt;
		}&lt;br /&gt;
		return true;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Notice that the &amp;lt;tt&amp;gt;example.php&amp;lt;/tt&amp;gt; file has six methods plus the constructor. These document the six possible events that you can use for plugins. In our example, we want to modify the article just before it is saved to the database. So we call our method (or function) &amp;quot;onContentBeforeSave&amp;quot;. This method name must be exactly as shown. The name is what tells Joomla! when to run our plugin.&lt;br /&gt;
&lt;br /&gt;
In standard Joomla!, when a user in the &amp;quot;Author&amp;quot; group first submits a new article, it is set to &amp;quot;Unpublished&amp;quot;. However, once the article has been published, this user can edit the article and it stays published. In our example, we want to change this so that, each time an article is edited by a user in the &amp;quot;Author&amp;quot; group, it gets changed back to &amp;quot;Unpublished&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
The code above does that. First, we get the user. Then, if the user is in the &amp;quot;Author&amp;quot; group, we change the article&#039;s &amp;quot;state&amp;quot; to zero, meaning &amp;quot;Unpublished&amp;quot;. Notice that the method has &amp;lt;tt&amp;gt;$article&amp;lt;/tt&amp;gt; as a parameter, so its fields and methods are all available to us.&lt;br /&gt;
&lt;br /&gt;
==Install the Plugin==&lt;br /&gt;
Once we have the plugin coded, we need to create a zip archive so we can install it in our Joomla! site. Here are the steps:&lt;br /&gt;
* Use any Zip or Gzip program to make a Zip or Gzip archive of the two files created above.&lt;br /&gt;
* In the back end of your Joomla! site, navigate to Extensions &amp;amp;rarr; Install / Uninstall.&lt;br /&gt;
* Press Browse and find your zip archive file.&lt;br /&gt;
* Press Upload File and Install. You should get a message indicating that the extension was installed successfully.&lt;br /&gt;
* Finally, navigate to Extensions &amp;amp;rarr; Plugin Manager, find the new plugin (called &amp;quot;Modify Edited Articles&amp;quot; based on the name in the XML file), and enable it.&lt;br /&gt;
At this point, you should be able to test that it is working as expected.&lt;br /&gt;
&lt;br /&gt;
==Add Standard Text==&lt;br /&gt;
Once we have the basic framework, changing the plugin to do other things is simple. For example, say we want to add standard text to any article submitted by a user in the &amp;quot;Author&amp;quot; group. Here is the code for the &amp;quot;onBeforeContentSave()&amp;quot; method:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
	function onContentBeforeSave( $context, &amp;amp;$article, $isNew )&lt;br /&gt;
	{&lt;br /&gt;
		$newText = &#039;&amp;lt;p&amp;gt;This is my new text to add to the article.&amp;lt;/p&amp;gt;&#039;;&lt;br /&gt;
		$user =&amp;amp; JFactory::getUser(); // get the user&lt;br /&gt;
		if ($user-&amp;gt;usertype == &#039;Author&#039;) { &lt;br /&gt;
			if ($article-&amp;gt;fulltext) {&lt;br /&gt;
				if (strpos($article-&amp;gt;fulltext, $newText) == 0) {&lt;br /&gt;
					$article-&amp;gt;fulltext .= $newText;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
			else {&lt;br /&gt;
				if (strpos($article-&amp;gt;introtext, $newText) == 0) {&lt;br /&gt;
					$article-&amp;gt;introtext .= $newText;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		return true;&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In this code, we have some standard text we put in the &amp;lt;tt&amp;gt;$newText&amp;lt;/tt&amp;gt; variable. Then we deal with a complication of the &amp;lt;tt&amp;gt;$article&amp;lt;/tt&amp;gt; object. Joomla! articles can have an optional &amp;quot;Read more...&amp;quot; break. If they don&#039;t have one, the entire text of the article is in the &amp;lt;tt&amp;gt;introtext&amp;lt;/tt&amp;gt; field. If there is a &amp;quot;Read more...&amp;quot; break, then the part of the article after the break is in the &amp;lt;tt&amp;gt;fulltext&amp;lt;/tt&amp;gt; field. &lt;br /&gt;
&lt;br /&gt;
So, in the code, we have to handle both cases. If there is something in &amp;lt;tt&amp;gt;fulltext&amp;lt;/tt&amp;gt;, then we add the standard text there. Otherwise, we add it to &amp;lt;tt&amp;gt;introtext&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
There is one other complication. We don&#039;t want to add the standard text if it already there. Otherwise, we would keep adding more copies of it each time the article is edited. So we test to see if it already part of the article&#039;s text and we only add it if it isn&#039;t already there.&lt;br /&gt;
&lt;br /&gt;
Notice that the second parameter of this method is &amp;lt;tt&amp;gt;$isNew&amp;lt;/tt&amp;gt;. This is a boolean that is &amp;lt;tt&amp;gt;true&amp;lt;/tt&amp;gt; if this is a new article. So we could test for that if we only wanted to add the text for new article submissions.&lt;br /&gt;
&lt;br /&gt;
==Set the Section or Category==&lt;br /&gt;
Setting the Section or Category ID of an article is very easy. For example, in the Sample Website, this code&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
   $article-&amp;gt;sectionid = &#039;4&#039;;&lt;br /&gt;
   $article-&amp;gt;catid = &#039;25&#039;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
would change the article&#039;s Section to &amp;quot;About Joomla!&amp;quot; and Category to &amp;quot;The Project&amp;quot;. Note that you need to use the &amp;quot;id&amp;quot; fields for the Section and Category. In this example, you also might want to remove these fields from the front-end form (by using a [[How_to_override_the_output_from_the_Joomla!_core|template override]])&lt;br /&gt;
&lt;br /&gt;
==Other Things We Can Do==&lt;br /&gt;
It is useful to understand that any of the article&#039;s fields are available here. Below is a partial list:&lt;br /&gt;
* title: article&#039;s title&lt;br /&gt;
* alias: article&#039;s alias&lt;br /&gt;
* state: 0 for unpublished, 1 for published, -1 for archived&lt;br /&gt;
* created: date created&lt;br /&gt;
* created_by: user id of author&lt;br /&gt;
* created_by_alias: author alias field&lt;br /&gt;
* modified: date last modified&lt;br /&gt;
* modified_by: user id of last author to modify&lt;br /&gt;
* metakey: Metadata Information / Keywords&lt;br /&gt;
* metadesc: Metadata Information / Description&lt;br /&gt;
* access: 0 for public, 1 for registered, 2 for special&lt;br /&gt;
&lt;br /&gt;
Also, there are other built-in events we can use for plugins, see [https://docs.joomla.org/Plugin/Events/Content|Plugin Events Content docs] for more info. These are documented in the &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt; file. In addition, there are other plugin types. See the [[Developers#Plugins|plugins section of the Wiki]] for more information. &lt;br /&gt;
&lt;br /&gt;
[[Category:Tips and tricks]]&lt;br /&gt;
[[Category:Tips and tricks 1.5]]&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Make_changes_to_an_article_automatically_using_a_plugin&amp;diff=719011</id>
		<title>Make changes to an article automatically using a plugin</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Make_changes_to_an_article_automatically_using_a_plugin&amp;diff=719011"/>
		<updated>2020-09-01T14:23:12Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
Plugins are the simplest extensions to write. A simple plugin requires only two files. Yet plugins can be extremely handy.&lt;br /&gt;
&lt;br /&gt;
One common case for using plugins is doing some customized processing every time an article is saved. For example:&lt;br /&gt;
* Change the published state of an article.&lt;br /&gt;
* Add standard text to articles.&lt;br /&gt;
* Set the Section or Category for an article.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see how you can use a simple plugin to do these types of tasks.&lt;br /&gt;
&lt;br /&gt;
==First Plugin==&lt;br /&gt;
A simple plugin has two files. One is an XML file that tells Joomla! how to install the plugin. The other is the actual plugin PHP code.&lt;br /&gt;
&lt;br /&gt;
To make it as easy as possible for people to write plugins, Joomla! includes example plugins in every installation. In our example, we are writing a &amp;quot;content&amp;quot; plugin, since we are working with articles. So the two example files we can use as guidelines are &amp;lt;tt&amp;gt;plugins/content/example.xml&amp;lt;/tt&amp;gt; amd &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The XML file for our example is called &amp;lt;tt&amp;gt;modifyarticle.xml&amp;lt;/tt&amp;gt;. We just copied  the file &amp;lt;tt&amp;gt;plugins/content/example.xml&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;modifyarticle.xml&amp;lt;/tt&amp;gt; and put it in a new folder outside of the Joomla! installation. (&#039;&#039;We will use the Joomla! install program later on to add this to our Joomla! system. So for now we want to keep this separate from Joomla!.&#039;&#039;) Then we edited it as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;install version=&amp;quot;1.5&amp;quot; type=&amp;quot;plugin&amp;quot; group=&amp;quot;content&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;Modify Edited Articles&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;creationDate&amp;gt;January 2009&amp;lt;/creationDate&amp;gt;&lt;br /&gt;
&amp;lt;author&amp;gt;Joomla Doc Team&amp;lt;/author&amp;gt;&lt;br /&gt;
&amp;lt;authorEmail&amp;gt;myemail@myemail.com&amp;lt;/authorEmail&amp;gt;&lt;br /&gt;
&amp;lt;authorUrl&amp;gt;http://joomlacode.org&amp;lt;/authorUrl&amp;gt;&lt;br /&gt;
&amp;lt;copyright&amp;gt;Copyright (c) 2009&amp;lt;/copyright&amp;gt;&lt;br /&gt;
&amp;lt;license&amp;gt;GPL&amp;lt;/license&amp;gt;&lt;br /&gt;
&amp;lt;version&amp;gt;1.0.0&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;lt;description&amp;gt;Example plugin for Joomla! wiki.&amp;lt;/description&amp;gt;&lt;br /&gt;
&amp;lt;files&amp;gt;&lt;br /&gt;
   &amp;lt;filename plugin=&amp;quot;modifyarticle&amp;quot;&amp;gt;modifyarticle.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
&amp;lt;/files&amp;gt;&lt;br /&gt;
&amp;lt;/install&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Next, we copy the file &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;modifyarticle.php&amp;lt;/tt&amp;gt; and put it in the same folder outside of the Joomla! installation. Then we edit this file so it reads as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
/**&lt;br /&gt;
 * @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.&lt;br /&gt;
 * @license		GNU/GPL, see LICENSE.php&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
// Check to ensure this file is included in Joomla!&lt;br /&gt;
defined( &#039;_JEXEC&#039; ) or die( &#039;Restricted access&#039; );&lt;br /&gt;
&lt;br /&gt;
jimport( &#039;joomla.plugin.plugin&#039; );&lt;br /&gt;
&lt;br /&gt;
class plgContentModifyArticle extends JPlugin&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Example before save content method&lt;br /&gt;
	 *&lt;br /&gt;
	 * Method is called right before content is saved into the database.&lt;br /&gt;
	 * Article object is passed by reference, so any changes will be saved!&lt;br /&gt;
	 * NOTE:  Returning false will abort the save with an error.&lt;br /&gt;
	 * 	You can set the error by calling $article-&amp;gt;setError($message)&lt;br /&gt;
	 *&lt;br /&gt;
	 * @param 	object		A JTableContent object&lt;br /&gt;
	 * @param 	bool		If the content is just about to be created&lt;br /&gt;
	 * @return	bool		If false, abort the save&lt;br /&gt;
	 */&lt;br /&gt;
	function onContentBeforeSave( $context, &amp;amp;$article, $isNew )&lt;br /&gt;
	{&lt;br /&gt;
		$user =&amp;amp; JFactory::getUser(); // get the user&lt;br /&gt;
		if ($user-&amp;gt;usertype == &#039;Author&#039;) { // unpublish if user is &amp;quot;Author&amp;quot;&lt;br /&gt;
			$article-&amp;gt;state = 0; // from dev 11:59&lt;br /&gt;
		}&lt;br /&gt;
		return true;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Notice that the &amp;lt;tt&amp;gt;example.php&amp;lt;/tt&amp;gt; file has six methods plus the constructor. These document the six possible events that you can use for plugins. In our example, we want to modify the article just before it is saved to the database. So we call our method (or function) &amp;quot;onContentBeforeSave&amp;quot;. This method name must be exactly as shown. The name is what tells Joomla! when to run our plugin.&lt;br /&gt;
&lt;br /&gt;
In standard Joomla!, when a user in the &amp;quot;Author&amp;quot; group first submits a new article, it is set to &amp;quot;Unpublished&amp;quot;. However, once the article has been published, this user can edit the article and it stays published. In our example, we want to change this so that, each time an article is edited by a user in the &amp;quot;Author&amp;quot; group, it gets changed back to &amp;quot;Unpublished&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
The code above does that. First, we get the user. Then, if the user is in the &amp;quot;Author&amp;quot; group, we change the article&#039;s &amp;quot;state&amp;quot; to zero, meaning &amp;quot;Unpublished&amp;quot;. Notice that the method has &amp;lt;tt&amp;gt;$article&amp;lt;/tt&amp;gt; as a parameter, so its fields and methods are all available to us.&lt;br /&gt;
&lt;br /&gt;
==Install the Plugin==&lt;br /&gt;
Once we have the plugin coded, we need to create a zip archive so we can install it in our Joomla! site. Here are the steps:&lt;br /&gt;
* Use any Zip or Gzip program to make a Zip or Gzip archive of the two files created above.&lt;br /&gt;
* In the back end of your Joomla! site, navigate to Extensions &amp;amp;rarr; Install / Uninstall.&lt;br /&gt;
* Press Browse and find your zip archive file.&lt;br /&gt;
* Press Upload File and Install. You should get a message indicating that the extension was installed successfully.&lt;br /&gt;
* Finally, navigate to Extensions &amp;amp;rarr; Plugin Manager, find the new plugin (called &amp;quot;Modify Edited Articles&amp;quot; based on the name in the XML file), and enable it.&lt;br /&gt;
At this point, you should be able to test that it is working as expected.&lt;br /&gt;
&lt;br /&gt;
==Add Standard Text==&lt;br /&gt;
Once we have the basic framework, changing the plugin to do other things is simple. For example, say we want to add standard text to any article submitted by a user in the &amp;quot;Author&amp;quot; group. Here is the code for the &amp;quot;onBeforeContentSave()&amp;quot; method:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
	function onContentBeforeSave( $context, &amp;amp;$article, $isNew )&lt;br /&gt;
	{&lt;br /&gt;
		$newText = &#039;&amp;lt;p&amp;gt;This is my new text to add to the article.&amp;lt;/p&amp;gt;&#039;;&lt;br /&gt;
		$user =&amp;amp; JFactory::getUser(); // get the user&lt;br /&gt;
		if ($user-&amp;gt;usertype == &#039;Author&#039;) { &lt;br /&gt;
			if ($article-&amp;gt;fulltext) {&lt;br /&gt;
				if (strpos($article-&amp;gt;fulltext, $newText) == 0) {&lt;br /&gt;
					$article-&amp;gt;fulltext .= $newText;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
			else {&lt;br /&gt;
				if (strpos($article-&amp;gt;introtext, $newText) == 0) {&lt;br /&gt;
					$article-&amp;gt;introtext .= $newText;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		return true;&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In this code, we have some standard text we put in the &amp;lt;tt&amp;gt;$newText&amp;lt;/tt&amp;gt; variable. Then we deal with a complication of the &amp;lt;tt&amp;gt;$article&amp;lt;/tt&amp;gt; object. Joomla! articles can have an optional &amp;quot;Read more...&amp;quot; break. If they don&#039;t have one, the entire text of the article is in the &amp;lt;tt&amp;gt;introtext&amp;lt;/tt&amp;gt; field. If there is a &amp;quot;Read more...&amp;quot; break, then the part of the article after the break is in the &amp;lt;tt&amp;gt;fulltext&amp;lt;/tt&amp;gt; field. &lt;br /&gt;
&lt;br /&gt;
So, in the code, we have to handle both cases. If there is something in &amp;lt;tt&amp;gt;fulltext&amp;lt;/tt&amp;gt;, then we add the standard text there. Otherwise, we add it to &amp;lt;tt&amp;gt;introtext&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
There is one other complication. We don&#039;t want to add the standard text if it already there. Otherwise, we would keep adding more copies of it each time the article is edited. So we test to see if it already part of the article&#039;s text and we only add it if it isn&#039;t already there.&lt;br /&gt;
&lt;br /&gt;
Notice that the second parameter of this method is &amp;lt;tt&amp;gt;$isNew&amp;lt;/tt&amp;gt;. This is a boolean that is &amp;lt;tt&amp;gt;true&amp;lt;/tt&amp;gt; if this is a new article. So we could test for that if we only wanted to add the text for new article submissions.&lt;br /&gt;
&lt;br /&gt;
==Set the Section or Category==&lt;br /&gt;
Setting the Section or Category ID of an article is very easy. For example, in the Sample Website, this code&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
   $article-&amp;gt;sectionid = &#039;4&#039;;&lt;br /&gt;
   $article-&amp;gt;catid = &#039;25&#039;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
would change the article&#039;s Section to &amp;quot;About Joomla!&amp;quot; and Category to &amp;quot;The Project&amp;quot;. Note that you need to use the &amp;quot;id&amp;quot; fields for the Section and Category. In this example, you also might want to remove these fields from the front-end form (by using a [[How_to_override_the_output_from_the_Joomla!_core|template override]])&lt;br /&gt;
&lt;br /&gt;
==Other Things We Can Do==&lt;br /&gt;
It is useful to understand that any of the article&#039;s fields are available here. Below is a partial list:&lt;br /&gt;
* title: article&#039;s title&lt;br /&gt;
* alias: article&#039;s alias&lt;br /&gt;
* state: 0 for unpublished, 1 for published, -1 for archived&lt;br /&gt;
* created: date created&lt;br /&gt;
* created_by: user id of author&lt;br /&gt;
* created_by_alias: author alias field&lt;br /&gt;
* modified: date last modified&lt;br /&gt;
* modified_by: user id of last author to modify&lt;br /&gt;
* metakey: Metadata Information / Keywords&lt;br /&gt;
* metadesc: Metadata Information / Description&lt;br /&gt;
* access: 0 for public, 1 for registered, 2 for special&lt;br /&gt;
&lt;br /&gt;
Also, there are other built-in events we can use for plugins, see [[https://docs.joomla.org/Plugin/Events/Content|Plugin Events Content docs]] for more info. These are documented in the &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt; file. In addition, there are other plugin types. See the [[Developers#Plugins|plugins section of the Wiki]] for more information. &lt;br /&gt;
&lt;br /&gt;
[[Category:Tips and tricks]]&lt;br /&gt;
[[Category:Tips and tricks 1.5]]&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Make_changes_to_an_article_automatically_using_a_plugin&amp;diff=719009</id>
		<title>Make changes to an article automatically using a plugin</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Make_changes_to_an_article_automatically_using_a_plugin&amp;diff=719009"/>
		<updated>2020-09-01T14:22:37Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
Plugins are the simplest extensions to write. A simple plugin requires only two files. Yet plugins can be extremely handy.&lt;br /&gt;
&lt;br /&gt;
One common case for using plugins is doing some customized processing every time an article is saved. For example:&lt;br /&gt;
* Change the published state of an article.&lt;br /&gt;
* Add standard text to articles.&lt;br /&gt;
* Set the Section or Category for an article.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see how you can use a simple plugin to do these types of tasks.&lt;br /&gt;
&lt;br /&gt;
==First Plugin==&lt;br /&gt;
A simple plugin has two files. One is an XML file that tells Joomla! how to install the plugin. The other is the actual plugin PHP code.&lt;br /&gt;
&lt;br /&gt;
To make it as easy as possible for people to write plugins, Joomla! includes example plugins in every installation. In our example, we are writing a &amp;quot;content&amp;quot; plugin, since we are working with articles. So the two example files we can use as guidelines are &amp;lt;tt&amp;gt;plugins/content/example.xml&amp;lt;/tt&amp;gt; amd &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The XML file for our example is called &amp;lt;tt&amp;gt;modifyarticle.xml&amp;lt;/tt&amp;gt;. We just copied  the file &amp;lt;tt&amp;gt;plugins/content/example.xml&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;modifyarticle.xml&amp;lt;/tt&amp;gt; and put it in a new folder outside of the Joomla! installation. (&#039;&#039;We will use the Joomla! install program later on to add this to our Joomla! system. So for now we want to keep this separate from Joomla!.&#039;&#039;) Then we edited it as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;install version=&amp;quot;1.5&amp;quot; type=&amp;quot;plugin&amp;quot; group=&amp;quot;content&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;Modify Edited Articles&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;creationDate&amp;gt;January 2009&amp;lt;/creationDate&amp;gt;&lt;br /&gt;
&amp;lt;author&amp;gt;Joomla Doc Team&amp;lt;/author&amp;gt;&lt;br /&gt;
&amp;lt;authorEmail&amp;gt;myemail@myemail.com&amp;lt;/authorEmail&amp;gt;&lt;br /&gt;
&amp;lt;authorUrl&amp;gt;http://joomlacode.org&amp;lt;/authorUrl&amp;gt;&lt;br /&gt;
&amp;lt;copyright&amp;gt;Copyright (c) 2009&amp;lt;/copyright&amp;gt;&lt;br /&gt;
&amp;lt;license&amp;gt;GPL&amp;lt;/license&amp;gt;&lt;br /&gt;
&amp;lt;version&amp;gt;1.0.0&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;lt;description&amp;gt;Example plugin for Joomla! wiki.&amp;lt;/description&amp;gt;&lt;br /&gt;
&amp;lt;files&amp;gt;&lt;br /&gt;
   &amp;lt;filename plugin=&amp;quot;modifyarticle&amp;quot;&amp;gt;modifyarticle.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
&amp;lt;/files&amp;gt;&lt;br /&gt;
&amp;lt;/install&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Next, we copy the file &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;modifyarticle.php&amp;lt;/tt&amp;gt; and put it in the same folder outside of the Joomla! installation. Then we edit this file so it reads as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
/**&lt;br /&gt;
 * @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.&lt;br /&gt;
 * @license		GNU/GPL, see LICENSE.php&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
// Check to ensure this file is included in Joomla!&lt;br /&gt;
defined( &#039;_JEXEC&#039; ) or die( &#039;Restricted access&#039; );&lt;br /&gt;
&lt;br /&gt;
jimport( &#039;joomla.plugin.plugin&#039; );&lt;br /&gt;
&lt;br /&gt;
class plgContentModifyArticle extends JPlugin&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Example before save content method&lt;br /&gt;
	 *&lt;br /&gt;
	 * Method is called right before content is saved into the database.&lt;br /&gt;
	 * Article object is passed by reference, so any changes will be saved!&lt;br /&gt;
	 * NOTE:  Returning false will abort the save with an error.&lt;br /&gt;
	 * 	You can set the error by calling $article-&amp;gt;setError($message)&lt;br /&gt;
	 *&lt;br /&gt;
	 * @param 	object		A JTableContent object&lt;br /&gt;
	 * @param 	bool		If the content is just about to be created&lt;br /&gt;
	 * @return	bool		If false, abort the save&lt;br /&gt;
	 */&lt;br /&gt;
	function onContentBeforeSave( $context, &amp;amp;$article, $isNew )&lt;br /&gt;
	{&lt;br /&gt;
		$user =&amp;amp; JFactory::getUser(); // get the user&lt;br /&gt;
		if ($user-&amp;gt;usertype == &#039;Author&#039;) { // unpublish if user is &amp;quot;Author&amp;quot;&lt;br /&gt;
			$article-&amp;gt;state = 0; // from dev 11:59&lt;br /&gt;
		}&lt;br /&gt;
		return true;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Notice that the &amp;lt;tt&amp;gt;example.php&amp;lt;/tt&amp;gt; file has six methods plus the constructor. These document the six possible events that you can use for plugins. In our example, we want to modify the article just before it is saved to the database. So we call our method (or function) &amp;quot;onContentBeforeSave&amp;quot;. This method name must be exactly as shown. The name is what tells Joomla! when to run our plugin.&lt;br /&gt;
&lt;br /&gt;
In standard Joomla!, when a user in the &amp;quot;Author&amp;quot; group first submits a new article, it is set to &amp;quot;Unpublished&amp;quot;. However, once the article has been published, this user can edit the article and it stays published. In our example, we want to change this so that, each time an article is edited by a user in the &amp;quot;Author&amp;quot; group, it gets changed back to &amp;quot;Unpublished&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
The code above does that. First, we get the user. Then, if the user is in the &amp;quot;Author&amp;quot; group, we change the article&#039;s &amp;quot;state&amp;quot; to zero, meaning &amp;quot;Unpublished&amp;quot;. Notice that the method has &amp;lt;tt&amp;gt;$article&amp;lt;/tt&amp;gt; as a parameter, so its fields and methods are all available to us.&lt;br /&gt;
&lt;br /&gt;
==Install the Plugin==&lt;br /&gt;
Once we have the plugin coded, we need to create a zip archive so we can install it in our Joomla! site. Here are the steps:&lt;br /&gt;
* Use any Zip or Gzip program to make a Zip or Gzip archive of the two files created above.&lt;br /&gt;
* In the back end of your Joomla! site, navigate to Extensions &amp;amp;rarr; Install / Uninstall.&lt;br /&gt;
* Press Browse and find your zip archive file.&lt;br /&gt;
* Press Upload File and Install. You should get a message indicating that the extension was installed successfully.&lt;br /&gt;
* Finally, navigate to Extensions &amp;amp;rarr; Plugin Manager, find the new plugin (called &amp;quot;Modify Edited Articles&amp;quot; based on the name in the XML file), and enable it.&lt;br /&gt;
At this point, you should be able to test that it is working as expected.&lt;br /&gt;
&lt;br /&gt;
==Add Standard Text==&lt;br /&gt;
Once we have the basic framework, changing the plugin to do other things is simple. For example, say we want to add standard text to any article submitted by a user in the &amp;quot;Author&amp;quot; group. Here is the code for the &amp;quot;onBeforeContentSave()&amp;quot; method:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
	function onContentBeforeSave( $context, &amp;amp;$article, $isNew )&lt;br /&gt;
	{&lt;br /&gt;
		$newText = &#039;&amp;lt;p&amp;gt;This is my new text to add to the article.&amp;lt;/p&amp;gt;&#039;;&lt;br /&gt;
		$user =&amp;amp; JFactory::getUser(); // get the user&lt;br /&gt;
		if ($user-&amp;gt;usertype == &#039;Author&#039;) { &lt;br /&gt;
			if ($article-&amp;gt;fulltext) {&lt;br /&gt;
				if (strpos($article-&amp;gt;fulltext, $newText) == 0) {&lt;br /&gt;
					$article-&amp;gt;fulltext .= $newText;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
			else {&lt;br /&gt;
				if (strpos($article-&amp;gt;introtext, $newText) == 0) {&lt;br /&gt;
					$article-&amp;gt;introtext .= $newText;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		return true;&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In this code, we have some standard text we put in the &amp;lt;tt&amp;gt;$newText&amp;lt;/tt&amp;gt; variable. Then we deal with a complication of the &amp;lt;tt&amp;gt;$article&amp;lt;/tt&amp;gt; object. Joomla! articles can have an optional &amp;quot;Read more...&amp;quot; break. If they don&#039;t have one, the entire text of the article is in the &amp;lt;tt&amp;gt;introtext&amp;lt;/tt&amp;gt; field. If there is a &amp;quot;Read more...&amp;quot; break, then the part of the article after the break is in the &amp;lt;tt&amp;gt;fulltext&amp;lt;/tt&amp;gt; field. &lt;br /&gt;
&lt;br /&gt;
So, in the code, we have to handle both cases. If there is something in &amp;lt;tt&amp;gt;fulltext&amp;lt;/tt&amp;gt;, then we add the standard text there. Otherwise, we add it to &amp;lt;tt&amp;gt;introtext&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
There is one other complication. We don&#039;t want to add the standard text if it already there. Otherwise, we would keep adding more copies of it each time the article is edited. So we test to see if it already part of the article&#039;s text and we only add it if it isn&#039;t already there.&lt;br /&gt;
&lt;br /&gt;
Notice that the second parameter of this method is &amp;lt;tt&amp;gt;$isNew&amp;lt;/tt&amp;gt;. This is a boolean that is &amp;lt;tt&amp;gt;true&amp;lt;/tt&amp;gt; if this is a new article. So we could test for that if we only wanted to add the text for new article submissions.&lt;br /&gt;
&lt;br /&gt;
==Set the Section or Category==&lt;br /&gt;
Setting the Section or Category ID of an article is very easy. For example, in the Sample Website, this code&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
   $article-&amp;gt;sectionid = &#039;4&#039;;&lt;br /&gt;
   $article-&amp;gt;catid = &#039;25&#039;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
would change the article&#039;s Section to &amp;quot;About Joomla!&amp;quot; and Category to &amp;quot;The Project&amp;quot;. Note that you need to use the &amp;quot;id&amp;quot; fields for the Section and Category. In this example, you also might want to remove these fields from the front-end form (by using a [[How_to_override_the_output_from_the_Joomla!_core|template override]])&lt;br /&gt;
&lt;br /&gt;
==Other Things We Can Do==&lt;br /&gt;
It is useful to understand that any of the article&#039;s fields are available here. Below is a partial list:&lt;br /&gt;
* title: article&#039;s title&lt;br /&gt;
* alias: article&#039;s alias&lt;br /&gt;
* state: 0 for unpublished, 1 for published, -1 for archived&lt;br /&gt;
* created: date created&lt;br /&gt;
* created_by: user id of author&lt;br /&gt;
* created_by_alias: author alias field&lt;br /&gt;
* modified: date last modified&lt;br /&gt;
* modified_by: user id of last author to modify&lt;br /&gt;
* metakey: Metadata Information / Keywords&lt;br /&gt;
* metadesc: Metadata Information / Description&lt;br /&gt;
* access: 0 for public, 1 for registered, 2 for special&lt;br /&gt;
&lt;br /&gt;
Also, there are other built-in events we can use for plugins, see [[https://docs.joomla.org/Plugin/Events/Content|Plugin/Events/Content docs]] for more info. These are documented in the &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt; file. In addition, there are other plugin types. See the [[Developers#Plugins|plugins section of the Wiki]] for more information. &lt;br /&gt;
&lt;br /&gt;
[[Category:Tips and tricks]]&lt;br /&gt;
[[Category:Tips and tricks 1.5]]&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Make_changes_to_an_article_automatically_using_a_plugin&amp;diff=719008</id>
		<title>Make changes to an article automatically using a plugin</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Make_changes_to_an_article_automatically_using_a_plugin&amp;diff=719008"/>
		<updated>2020-09-01T14:21:54Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
Plugins are the simplest extensions to write. A simple plugin requires only two files. Yet plugins can be extremely handy.&lt;br /&gt;
&lt;br /&gt;
One common case for using plugins is doing some customized processing every time an article is saved. For example:&lt;br /&gt;
* Change the published state of an article.&lt;br /&gt;
* Add standard text to articles.&lt;br /&gt;
* Set the Section or Category for an article.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see how you can use a simple plugin to do these types of tasks.&lt;br /&gt;
&lt;br /&gt;
==First Plugin==&lt;br /&gt;
A simple plugin has two files. One is an XML file that tells Joomla! how to install the plugin. The other is the actual plugin PHP code.&lt;br /&gt;
&lt;br /&gt;
To make it as easy as possible for people to write plugins, Joomla! includes example plugins in every installation. In our example, we are writing a &amp;quot;content&amp;quot; plugin, since we are working with articles. So the two example files we can use as guidelines are &amp;lt;tt&amp;gt;plugins/content/example.xml&amp;lt;/tt&amp;gt; amd &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The XML file for our example is called &amp;lt;tt&amp;gt;modifyarticle.xml&amp;lt;/tt&amp;gt;. We just copied  the file &amp;lt;tt&amp;gt;plugins/content/example.xml&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;modifyarticle.xml&amp;lt;/tt&amp;gt; and put it in a new folder outside of the Joomla! installation. (&#039;&#039;We will use the Joomla! install program later on to add this to our Joomla! system. So for now we want to keep this separate from Joomla!.&#039;&#039;) Then we edited it as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;install version=&amp;quot;1.5&amp;quot; type=&amp;quot;plugin&amp;quot; group=&amp;quot;content&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;Modify Edited Articles&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;creationDate&amp;gt;January 2009&amp;lt;/creationDate&amp;gt;&lt;br /&gt;
&amp;lt;author&amp;gt;Joomla Doc Team&amp;lt;/author&amp;gt;&lt;br /&gt;
&amp;lt;authorEmail&amp;gt;myemail@myemail.com&amp;lt;/authorEmail&amp;gt;&lt;br /&gt;
&amp;lt;authorUrl&amp;gt;http://joomlacode.org&amp;lt;/authorUrl&amp;gt;&lt;br /&gt;
&amp;lt;copyright&amp;gt;Copyright (c) 2009&amp;lt;/copyright&amp;gt;&lt;br /&gt;
&amp;lt;license&amp;gt;GPL&amp;lt;/license&amp;gt;&lt;br /&gt;
&amp;lt;version&amp;gt;1.0.0&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;lt;description&amp;gt;Example plugin for Joomla! wiki.&amp;lt;/description&amp;gt;&lt;br /&gt;
&amp;lt;files&amp;gt;&lt;br /&gt;
   &amp;lt;filename plugin=&amp;quot;modifyarticle&amp;quot;&amp;gt;modifyarticle.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
&amp;lt;/files&amp;gt;&lt;br /&gt;
&amp;lt;/install&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Next, we copy the file &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;modifyarticle.php&amp;lt;/tt&amp;gt; and put it in the same folder outside of the Joomla! installation. Then we edit this file so it reads as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
/**&lt;br /&gt;
 * @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.&lt;br /&gt;
 * @license		GNU/GPL, see LICENSE.php&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
// Check to ensure this file is included in Joomla!&lt;br /&gt;
defined( &#039;_JEXEC&#039; ) or die( &#039;Restricted access&#039; );&lt;br /&gt;
&lt;br /&gt;
jimport( &#039;joomla.plugin.plugin&#039; );&lt;br /&gt;
&lt;br /&gt;
class plgContentModifyArticle extends JPlugin&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Example before save content method&lt;br /&gt;
	 *&lt;br /&gt;
	 * Method is called right before content is saved into the database.&lt;br /&gt;
	 * Article object is passed by reference, so any changes will be saved!&lt;br /&gt;
	 * NOTE:  Returning false will abort the save with an error.&lt;br /&gt;
	 * 	You can set the error by calling $article-&amp;gt;setError($message)&lt;br /&gt;
	 *&lt;br /&gt;
	 * @param 	object		A JTableContent object&lt;br /&gt;
	 * @param 	bool		If the content is just about to be created&lt;br /&gt;
	 * @return	bool		If false, abort the save&lt;br /&gt;
	 */&lt;br /&gt;
	function onContentBeforeSave( $context, &amp;amp;$article, $isNew )&lt;br /&gt;
	{&lt;br /&gt;
		$user =&amp;amp; JFactory::getUser(); // get the user&lt;br /&gt;
		if ($user-&amp;gt;usertype == &#039;Author&#039;) { // unpublish if user is &amp;quot;Author&amp;quot;&lt;br /&gt;
			$article-&amp;gt;state = 0; // from dev 11:59&lt;br /&gt;
		}&lt;br /&gt;
		return true;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Notice that the &amp;lt;tt&amp;gt;example.php&amp;lt;/tt&amp;gt; file has six methods plus the constructor. These document the six possible events that you can use for plugins. In our example, we want to modify the article just before it is saved to the database. So we call our method (or function) &amp;quot;onContentBeforeSave&amp;quot;. This method name must be exactly as shown. The name is what tells Joomla! when to run our plugin.&lt;br /&gt;
&lt;br /&gt;
In standard Joomla!, when a user in the &amp;quot;Author&amp;quot; group first submits a new article, it is set to &amp;quot;Unpublished&amp;quot;. However, once the article has been published, this user can edit the article and it stays published. In our example, we want to change this so that, each time an article is edited by a user in the &amp;quot;Author&amp;quot; group, it gets changed back to &amp;quot;Unpublished&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
The code above does that. First, we get the user. Then, if the user is in the &amp;quot;Author&amp;quot; group, we change the article&#039;s &amp;quot;state&amp;quot; to zero, meaning &amp;quot;Unpublished&amp;quot;. Notice that the method has &amp;lt;tt&amp;gt;$article&amp;lt;/tt&amp;gt; as a parameter, so its fields and methods are all available to us.&lt;br /&gt;
&lt;br /&gt;
==Install the Plugin==&lt;br /&gt;
Once we have the plugin coded, we need to create a zip archive so we can install it in our Joomla! site. Here are the steps:&lt;br /&gt;
* Use any Zip or Gzip program to make a Zip or Gzip archive of the two files created above.&lt;br /&gt;
* In the back end of your Joomla! site, navigate to Extensions &amp;amp;rarr; Install / Uninstall.&lt;br /&gt;
* Press Browse and find your zip archive file.&lt;br /&gt;
* Press Upload File and Install. You should get a message indicating that the extension was installed successfully.&lt;br /&gt;
* Finally, navigate to Extensions &amp;amp;rarr; Plugin Manager, find the new plugin (called &amp;quot;Modify Edited Articles&amp;quot; based on the name in the XML file), and enable it.&lt;br /&gt;
At this point, you should be able to test that it is working as expected.&lt;br /&gt;
&lt;br /&gt;
==Add Standard Text==&lt;br /&gt;
Once we have the basic framework, changing the plugin to do other things is simple. For example, say we want to add standard text to any article submitted by a user in the &amp;quot;Author&amp;quot; group. Here is the code for the &amp;quot;onBeforeContentSave()&amp;quot; method:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
	function onContentBeforeSave( $context, &amp;amp;$article, $isNew )&lt;br /&gt;
	{&lt;br /&gt;
		$newText = &#039;&amp;lt;p&amp;gt;This is my new text to add to the article.&amp;lt;/p&amp;gt;&#039;;&lt;br /&gt;
		$user =&amp;amp; JFactory::getUser(); // get the user&lt;br /&gt;
		if ($user-&amp;gt;usertype == &#039;Author&#039;) { &lt;br /&gt;
			if ($article-&amp;gt;fulltext) {&lt;br /&gt;
				if (strpos($article-&amp;gt;fulltext, $newText) == 0) {&lt;br /&gt;
					$article-&amp;gt;fulltext .= $newText;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
			else {&lt;br /&gt;
				if (strpos($article-&amp;gt;introtext, $newText) == 0) {&lt;br /&gt;
					$article-&amp;gt;introtext .= $newText;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		return true;&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In this code, we have some standard text we put in the &amp;lt;tt&amp;gt;$newText&amp;lt;/tt&amp;gt; variable. Then we deal with a complication of the &amp;lt;tt&amp;gt;$article&amp;lt;/tt&amp;gt; object. Joomla! articles can have an optional &amp;quot;Read more...&amp;quot; break. If they don&#039;t have one, the entire text of the article is in the &amp;lt;tt&amp;gt;introtext&amp;lt;/tt&amp;gt; field. If there is a &amp;quot;Read more...&amp;quot; break, then the part of the article after the break is in the &amp;lt;tt&amp;gt;fulltext&amp;lt;/tt&amp;gt; field. &lt;br /&gt;
&lt;br /&gt;
So, in the code, we have to handle both cases. If there is something in &amp;lt;tt&amp;gt;fulltext&amp;lt;/tt&amp;gt;, then we add the standard text there. Otherwise, we add it to &amp;lt;tt&amp;gt;introtext&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
There is one other complication. We don&#039;t want to add the standard text if it already there. Otherwise, we would keep adding more copies of it each time the article is edited. So we test to see if it already part of the article&#039;s text and we only add it if it isn&#039;t already there.&lt;br /&gt;
&lt;br /&gt;
Notice that the second parameter of this method is &amp;lt;tt&amp;gt;$isNew&amp;lt;/tt&amp;gt;. This is a boolean that is &amp;lt;tt&amp;gt;true&amp;lt;/tt&amp;gt; if this is a new article. So we could test for that if we only wanted to add the text for new article submissions.&lt;br /&gt;
&lt;br /&gt;
==Set the Section or Category==&lt;br /&gt;
Setting the Section or Category ID of an article is very easy. For example, in the Sample Website, this code&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
   $article-&amp;gt;sectionid = &#039;4&#039;;&lt;br /&gt;
   $article-&amp;gt;catid = &#039;25&#039;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
would change the article&#039;s Section to &amp;quot;About Joomla!&amp;quot; and Category to &amp;quot;The Project&amp;quot;. Note that you need to use the &amp;quot;id&amp;quot; fields for the Section and Category. In this example, you also might want to remove these fields from the front-end form (by using a [[How_to_override_the_output_from_the_Joomla!_core|template override]])&lt;br /&gt;
&lt;br /&gt;
==Other Things We Can Do==&lt;br /&gt;
It is useful to understand that any of the article&#039;s fields are available here. Below is a partial list:&lt;br /&gt;
* title: article&#039;s title&lt;br /&gt;
* alias: article&#039;s alias&lt;br /&gt;
* state: 0 for unpublished, 1 for published, -1 for archived&lt;br /&gt;
* created: date created&lt;br /&gt;
* created_by: user id of author&lt;br /&gt;
* created_by_alias: author alias field&lt;br /&gt;
* modified: date last modified&lt;br /&gt;
* modified_by: user id of last author to modify&lt;br /&gt;
* metakey: Metadata Information / Keywords&lt;br /&gt;
* metadesc: Metadata Information / Description&lt;br /&gt;
* access: 0 for public, 1 for registered, 2 for special&lt;br /&gt;
&lt;br /&gt;
Also, there are other built-in events we can use for plugins, see [[https://docs.joomla.org/Plugin/Events/Content]] for more info. These are documented in the &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt; file. In addition, there are other plugin types. See the [[Developers#Plugins|plugins section of the Wiki]] for more information. &lt;br /&gt;
&lt;br /&gt;
[[Category:Tips and tricks]]&lt;br /&gt;
[[Category:Tips and tricks 1.5]]&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Make_changes_to_an_article_automatically_using_a_plugin&amp;diff=719007</id>
		<title>Make changes to an article automatically using a plugin</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Make_changes_to_an_article_automatically_using_a_plugin&amp;diff=719007"/>
		<updated>2020-09-01T14:12:47Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: updating from onBeforeContentSave to onContentBeforeSave and removing support for php4&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
Plugins are the simplest extensions to write. A simple plugin requires only two files. Yet plugins can be extremely handy.&lt;br /&gt;
&lt;br /&gt;
One common case for using plugins is doing some customized processing every time an article is saved. For example:&lt;br /&gt;
* Change the published state of an article.&lt;br /&gt;
* Add standard text to articles.&lt;br /&gt;
* Set the Section or Category for an article.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see how you can use a simple plugin to do these types of tasks.&lt;br /&gt;
&lt;br /&gt;
==First Plugin==&lt;br /&gt;
A simple plugin has two files. One is an XML file that tells Joomla! how to install the plugin. The other is the actual plugin PHP code.&lt;br /&gt;
&lt;br /&gt;
To make it as easy as possible for people to write plugins, Joomla! includes example plugins in every installation. In our example, we are writing a &amp;quot;content&amp;quot; plugin, since we are working with articles. So the two example files we can use as guidelines are &amp;lt;tt&amp;gt;plugins/content/example.xml&amp;lt;/tt&amp;gt; amd &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The XML file for our example is called &amp;lt;tt&amp;gt;modifyarticle.xml&amp;lt;/tt&amp;gt;. We just copied  the file &amp;lt;tt&amp;gt;plugins/content/example.xml&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;modifyarticle.xml&amp;lt;/tt&amp;gt; and put it in a new folder outside of the Joomla! installation. (&#039;&#039;We will use the Joomla! install program later on to add this to our Joomla! system. So for now we want to keep this separate from Joomla!.&#039;&#039;) Then we edited it as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;install version=&amp;quot;1.5&amp;quot; type=&amp;quot;plugin&amp;quot; group=&amp;quot;content&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;name&amp;gt;Modify Edited Articles&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;creationDate&amp;gt;January 2009&amp;lt;/creationDate&amp;gt;&lt;br /&gt;
&amp;lt;author&amp;gt;Joomla Doc Team&amp;lt;/author&amp;gt;&lt;br /&gt;
&amp;lt;authorEmail&amp;gt;myemail@myemail.com&amp;lt;/authorEmail&amp;gt;&lt;br /&gt;
&amp;lt;authorUrl&amp;gt;http://joomlacode.org&amp;lt;/authorUrl&amp;gt;&lt;br /&gt;
&amp;lt;copyright&amp;gt;Copyright (c) 2009&amp;lt;/copyright&amp;gt;&lt;br /&gt;
&amp;lt;license&amp;gt;GPL&amp;lt;/license&amp;gt;&lt;br /&gt;
&amp;lt;version&amp;gt;1.0.0&amp;lt;/version&amp;gt;&lt;br /&gt;
&amp;lt;description&amp;gt;Example plugin for Joomla! wiki.&amp;lt;/description&amp;gt;&lt;br /&gt;
&amp;lt;files&amp;gt;&lt;br /&gt;
   &amp;lt;filename plugin=&amp;quot;modifyarticle&amp;quot;&amp;gt;modifyarticle.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
&amp;lt;/files&amp;gt;&lt;br /&gt;
&amp;lt;/install&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Next, we copy the file &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;modifyarticle.php&amp;lt;/tt&amp;gt; and put it in the same folder outside of the Joomla! installation. Then we edit this file so it reads as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
/**&lt;br /&gt;
 * @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.&lt;br /&gt;
 * @license		GNU/GPL, see LICENSE.php&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
// Check to ensure this file is included in Joomla!&lt;br /&gt;
defined( &#039;_JEXEC&#039; ) or die( &#039;Restricted access&#039; );&lt;br /&gt;
&lt;br /&gt;
jimport( &#039;joomla.plugin.plugin&#039; );&lt;br /&gt;
&lt;br /&gt;
class plgContentModifyArticle extends JPlugin&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Example before save content method&lt;br /&gt;
	 *&lt;br /&gt;
	 * Method is called right before content is saved into the database.&lt;br /&gt;
	 * Article object is passed by reference, so any changes will be saved!&lt;br /&gt;
	 * NOTE:  Returning false will abort the save with an error.&lt;br /&gt;
	 * 	You can set the error by calling $article-&amp;gt;setError($message)&lt;br /&gt;
	 *&lt;br /&gt;
	 * @param 	object		A JTableContent object&lt;br /&gt;
	 * @param 	bool		If the content is just about to be created&lt;br /&gt;
	 * @return	bool		If false, abort the save&lt;br /&gt;
	 */&lt;br /&gt;
	function onContentBeforeSave( $context, &amp;amp;$article, $isNew )&lt;br /&gt;
	{&lt;br /&gt;
		$user =&amp;amp; JFactory::getUser(); // get the user&lt;br /&gt;
		if ($user-&amp;gt;usertype == &#039;Author&#039;) { // unpublish if user is &amp;quot;Author&amp;quot;&lt;br /&gt;
			$article-&amp;gt;state = 0; // from dev 11:59&lt;br /&gt;
		}&lt;br /&gt;
		return true;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Notice that the &amp;lt;tt&amp;gt;example.php&amp;lt;/tt&amp;gt; file has six methods plus the constructor. These document the six possible events that you can use for plugins. In our example, we want to modify the article just before it is saved to the database. So we call our method (or function) &amp;quot;onContentBeforeSave&amp;quot;. This method name must be exactly as shown. The name is what tells Joomla! when to run our plugin.&lt;br /&gt;
&lt;br /&gt;
In standard Joomla!, when a user in the &amp;quot;Author&amp;quot; group first submits a new article, it is set to &amp;quot;Unpublished&amp;quot;. However, once the article has been published, this user can edit the article and it stays published. In our example, we want to change this so that, each time an article is edited by a user in the &amp;quot;Author&amp;quot; group, it gets changed back to &amp;quot;Unpublished&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
The code above does that. First, we get the user. Then, if the user is in the &amp;quot;Author&amp;quot; group, we change the article&#039;s &amp;quot;state&amp;quot; to zero, meaning &amp;quot;Unpublished&amp;quot;. Notice that the method has &amp;lt;tt&amp;gt;$article&amp;lt;/tt&amp;gt; as a parameter, so its fields and methods are all available to us.&lt;br /&gt;
&lt;br /&gt;
==Install the Plugin==&lt;br /&gt;
Once we have the plugin coded, we need to create a zip archive so we can install it in our Joomla! site. Here are the steps:&lt;br /&gt;
* Use any Zip or Gzip program to make a Zip or Gzip archive of the two files created above.&lt;br /&gt;
* In the back end of your Joomla! site, navigate to Extensions &amp;amp;rarr; Install / Uninstall.&lt;br /&gt;
* Press Browse and find your zip archive file.&lt;br /&gt;
* Press Upload File and Install. You should get a message indicating that the extension was installed successfully.&lt;br /&gt;
* Finally, navigate to Extensions &amp;amp;rarr; Plugin Manager, find the new plugin (called &amp;quot;Modify Edited Articles&amp;quot; based on the name in the XML file), and enable it.&lt;br /&gt;
At this point, you should be able to test that it is working as expected.&lt;br /&gt;
&lt;br /&gt;
==Add Standard Text==&lt;br /&gt;
Once we have the basic framework, changing the plugin to do other things is simple. For example, say we want to add standard text to any article submitted by a user in the &amp;quot;Author&amp;quot; group. Here is the code for the &amp;quot;onBeforeContentSave()&amp;quot; method:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
	function onContentBeforeSave( $context, &amp;amp;$article, $isNew )&lt;br /&gt;
	{&lt;br /&gt;
		$newText = &#039;&amp;lt;p&amp;gt;This is my new text to add to the article.&amp;lt;/p&amp;gt;&#039;;&lt;br /&gt;
		$user =&amp;amp; JFactory::getUser(); // get the user&lt;br /&gt;
		if ($user-&amp;gt;usertype == &#039;Author&#039;) { &lt;br /&gt;
			if ($article-&amp;gt;fulltext) {&lt;br /&gt;
				if (strpos($article-&amp;gt;fulltext, $newText) == 0) {&lt;br /&gt;
					$article-&amp;gt;fulltext .= $newText;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
			else {&lt;br /&gt;
				if (strpos($article-&amp;gt;introtext, $newText) == 0) {&lt;br /&gt;
					$article-&amp;gt;introtext .= $newText;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		return true;&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In this code, we have some standard text we put in the &amp;lt;tt&amp;gt;$newText&amp;lt;/tt&amp;gt; variable. Then we deal with a complication of the &amp;lt;tt&amp;gt;$article&amp;lt;/tt&amp;gt; object. Joomla! articles can have an optional &amp;quot;Read more...&amp;quot; break. If they don&#039;t have one, the entire text of the article is in the &amp;lt;tt&amp;gt;introtext&amp;lt;/tt&amp;gt; field. If there is a &amp;quot;Read more...&amp;quot; break, then the part of the article after the break is in the &amp;lt;tt&amp;gt;fulltext&amp;lt;/tt&amp;gt; field. &lt;br /&gt;
&lt;br /&gt;
So, in the code, we have to handle both cases. If there is something in &amp;lt;tt&amp;gt;fulltext&amp;lt;/tt&amp;gt;, then we add the standard text there. Otherwise, we add it to &amp;lt;tt&amp;gt;introtext&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
There is one other complication. We don&#039;t want to add the standard text if it already there. Otherwise, we would keep adding more copies of it each time the article is edited. So we test to see if it already part of the article&#039;s text and we only add it if it isn&#039;t already there.&lt;br /&gt;
&lt;br /&gt;
Notice that the second parameter of this method is &amp;lt;tt&amp;gt;$isNew&amp;lt;/tt&amp;gt;. This is a boolean that is &amp;lt;tt&amp;gt;true&amp;lt;/tt&amp;gt; if this is a new article. So we could test for that if we only wanted to add the text for new article submissions.&lt;br /&gt;
&lt;br /&gt;
==Set the Section or Category==&lt;br /&gt;
Setting the Section or Category ID of an article is very easy. For example, in the Sample Website, this code&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
   $article-&amp;gt;sectionid = &#039;4&#039;;&lt;br /&gt;
   $article-&amp;gt;catid = &#039;25&#039;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
would change the article&#039;s Section to &amp;quot;About Joomla!&amp;quot; and Category to &amp;quot;The Project&amp;quot;. Note that you need to use the &amp;quot;id&amp;quot; fields for the Section and Category. In this example, you also might want to remove these fields from the front-end form (by using a [[How_to_override_the_output_from_the_Joomla!_core|template override]])&lt;br /&gt;
&lt;br /&gt;
==Other Things We Can Do==&lt;br /&gt;
It is useful to understand that any of the article&#039;s fields are available here. Below is a partial list:&lt;br /&gt;
* title: article&#039;s title&lt;br /&gt;
* alias: article&#039;s alias&lt;br /&gt;
* state: 0 for unpublished, 1 for published, -1 for archived&lt;br /&gt;
* created: date created&lt;br /&gt;
* created_by: user id of author&lt;br /&gt;
* created_by_alias: author alias field&lt;br /&gt;
* modified: date last modified&lt;br /&gt;
* modified_by: user id of last author to modify&lt;br /&gt;
* metakey: Metadata Information / Keywords&lt;br /&gt;
* metadesc: Metadata Information / Description&lt;br /&gt;
* access: 0 for public, 1 for registered, 2 for special&lt;br /&gt;
&lt;br /&gt;
Also, there are other built-in events we can use for plugins. These are documented in the &amp;lt;tt&amp;gt;plugins/content/example.php&amp;lt;/tt&amp;gt; file. In addition, there are other plugin types. See the [[Developers#Plugins|plugins section of the Wiki]] for more information. &lt;br /&gt;
&lt;br /&gt;
[[Category:Tips and tricks]]&lt;br /&gt;
[[Category:Tips and tricks 1.5]]&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Inserting,_Updating_and_Removing_data_using_JDatabase&amp;diff=677833</id>
		<title>Inserting, Updating and Removing data using JDatabase</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Inserting,_Updating_and_Removing_data_using_JDatabase&amp;diff=677833"/>
		<updated>2020-06-08T10:21:10Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: insertid&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;&amp;lt;languages /&amp;gt;&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&amp;lt;noinclude&amp;gt;{{Joomla version|version=3.x}}{{Joomla version|version=2.5|status=eos}}&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
{{-}}&lt;br /&gt;
{{tip|&amp;lt;translate&amp;gt;&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
Note many examples online use &amp;lt;code&amp;gt;$db-&amp;gt;query()&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;$db-&amp;gt;execute()&amp;lt;/code&amp;gt;. This was the old method in Joomla 1.5 and 2.5 and will throw a deprecated notice in Joomla 3.0+.&amp;lt;/translate&amp;gt;|title=&amp;lt;translate&amp;gt;&amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
Version Note&amp;lt;/translate&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
This tutorial is split into two independent parts:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
* Inserting, updating and removing data from the database.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
* Selecting data from one or more tables and retrieving it in a variety of different forms.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
This section of the documentation looks at inserting, updating and removing data from a database table. To see the other part [[S:MyLanguage/Selecting_data_using_JDatabase|click here]]&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Introduction== &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
Joomla can use different kinds of SQL database systems and 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 you need just two 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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==The Query== &amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
Joomla&#039;s database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
The &amp;lt;tt&amp;gt;JDatabaseDriver::getQuery&amp;lt;/tt&amp;gt; takes an optional argument, $new, which can be true or false (the default being false).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source&#039;s query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer&#039;s source code.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==Inserting a Record== &amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
===Using SQL=== &amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:19--&amp;gt;&lt;br /&gt;
The JDatabaseQuery class provides a number of methods for building insert queries, the most common being&amp;lt;/translate&amp;gt; [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#insert insert], [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#columns columns] &amp;lt;translate&amp;gt;&amp;lt;!--T:37--&amp;gt;&lt;br /&gt;
and&amp;lt;/translate&amp;gt; [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#values values].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Insert columns.&lt;br /&gt;
$columns = array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;);&lt;br /&gt;
&lt;br /&gt;
// Insert values.&lt;br /&gt;
$values = array(1001, $db-&amp;gt;quote(&#039;custom.message&#039;), $db-&amp;gt;quote(&#039;Inserting a record using insert()&#039;), 1);&lt;br /&gt;
&lt;br /&gt;
// Prepare the insert query.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;insert($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;))&lt;br /&gt;
    -&amp;gt;columns($db-&amp;gt;quoteName($columns))&lt;br /&gt;
    -&amp;gt;values(implode(&#039;,&#039;, $values));&lt;br /&gt;
&lt;br /&gt;
// Set the query using our newly populated query object and execute it.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$db-&amp;gt;execute();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:42--&amp;gt;&lt;br /&gt;
(Here the &amp;lt;tt&amp;gt;quoteName()&amp;lt;/tt&amp;gt; function adds appropriate quotes around the table and column names to avoid conflicts with any database reserved word, now or in the future.)&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get the ID of the row that you just inserted, you can use the &#039;insertid&#039; method, for example.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get the row that was just inserted&lt;br /&gt;
$new_row_id = $db-&amp;gt;insertid();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
===Using an Object=== &amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
The &amp;lt;tt&amp;gt;JDatabaseDriver&amp;lt;/tt&amp;gt; class also provides a convenient method for saving an object directly to the database allowing us to add a record to a table without writing a single line of SQL.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create and populate an object.&lt;br /&gt;
$profile = new stdClass();&lt;br /&gt;
$profile-&amp;gt;user_id = 1001;&lt;br /&gt;
$profile-&amp;gt;profile_key=&#039;custom.message&#039;;&lt;br /&gt;
$profile-&amp;gt;profile_value=&#039;Inserting a record using insertObject()&#039;;&lt;br /&gt;
$profile-&amp;gt;ordering=1;&lt;br /&gt;
&lt;br /&gt;
// Insert the object into the user profile table.&lt;br /&gt;
$result = JFactory::getDbo()-&amp;gt;insertObject(&#039;#__user_profiles&#039;, $profile);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
Notice here that we do not need to escape the table name; the insertObject method does this for us.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:23--&amp;gt;&lt;br /&gt;
The insertObject method will throw a error if there is a problem inserting the record into the database table.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:24--&amp;gt;&lt;br /&gt;
If you are providing a unique primary key value (as in the example above), it is highly recommended that you select from the table by that column value before attempting an insert.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:38--&amp;gt;&lt;br /&gt;
If you are simply inserting the next row in your table (i.e. the database generates a primary key value), you can specify the primary key column-name as the third parameter of the insertObject() method and the method will update the object with the newly generated primary key value.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:39--&amp;gt;&lt;br /&gt;
For example, given the following statement:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=php&amp;gt;&lt;br /&gt;
&lt;br /&gt;
$result = $dbconnect-&amp;gt;insertObject(&#039;#__my_table&#039;, $object, &#039;primary_key&#039;); &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:40--&amp;gt;&lt;br /&gt;
after execution, $object-&amp;gt;primary_key will be updated with the newly inserted row&#039;s primary key value.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:41--&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;HINT:&#039;&#039;&#039; Set $object-&amp;gt;primary_key to null or 0 (zero) before inserting.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==Updating a Record== &amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
===Using SQL=== &amp;lt;!--T:26--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:27--&amp;gt;&lt;br /&gt;
The &amp;lt;tt&amp;gt;JDatabaseQuery&amp;lt;/tt&amp;gt; class also provides methods for building update queries, in particular [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#update update] and [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#set set]. We also reuse another method which we used when creating select statements, the where method.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Fields to update.&lt;br /&gt;
$fields = array(&lt;br /&gt;
    $db-&amp;gt;quoteName(&#039;profile_value&#039;) . &#039; = &#039; . $db-&amp;gt;quote(&#039;Updating custom message for user 1001.&#039;),&lt;br /&gt;
    $db-&amp;gt;quoteName(&#039;ordering&#039;) . &#039; = 2&#039;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
// Conditions for which records should be updated.&lt;br /&gt;
$conditions = array(&lt;br /&gt;
    $db-&amp;gt;quoteName(&#039;user_id&#039;) . &#039; = 42&#039;, &lt;br /&gt;
    $db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; = &#039; . $db-&amp;gt;quote(&#039;custom.message&#039;)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;update($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;))-&amp;gt;set($fields)-&amp;gt;where($conditions);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
$result = $db-&amp;gt;execute();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
===Using an Object === &amp;lt;!--T:28--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:29--&amp;gt;&lt;br /&gt;
Like &amp;lt;tt&amp;gt;insertObject&amp;lt;/tt&amp;gt;, the JDatabaseDriver class provides a convenience method for updating an object.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:30--&amp;gt;&lt;br /&gt;
Below we will update our custom table with new values using an existing id primary key:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create an object for the record we are going to update.&lt;br /&gt;
$object = new stdClass();&lt;br /&gt;
&lt;br /&gt;
// Must be a valid primary key value.&lt;br /&gt;
$object-&amp;gt;id = 1;&lt;br /&gt;
$object-&amp;gt;title = &#039;My Custom Record&#039;;&lt;br /&gt;
$object-&amp;gt;description = &#039;A custom record being updated in the database.&#039;;&lt;br /&gt;
&lt;br /&gt;
// Update their details in the users table using id as the primary key.&lt;br /&gt;
$result = JFactory::getDbo()-&amp;gt;updateObject(&#039;#__custom_table&#039;, $object, &#039;id&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:31--&amp;gt;&lt;br /&gt;
Just like insertObject, updateObject takes care of escaping table names for us.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:32--&amp;gt;&lt;br /&gt;
The updateObject method will throw a error if there is a problem updating the record into the database table.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:33--&amp;gt;&lt;br /&gt;
We need to ensure that the record already exists before attempting to update it, so we would probably add some kind of record check before executing the updateObject method.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==Deleting a Record== &amp;lt;!--T:34--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:35--&amp;gt;&lt;br /&gt;
Finally, there is also a delete method to remove records from the database.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// delete all custom keys for user 1001.&lt;br /&gt;
$conditions = array(&lt;br /&gt;
    $db-&amp;gt;quoteName(&#039;user_id&#039;) . &#039; = 1001&#039;, &lt;br /&gt;
    $db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; = &#039; . $db-&amp;gt;quote(&#039;custom.%&#039;)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;delete($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;));&lt;br /&gt;
$query-&amp;gt;where($conditions);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
$result = $db-&amp;gt;execute();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Sample Module Code == &amp;lt;!--T:43--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:44--&amp;gt;&lt;br /&gt;
Below is the code for a simple Joomla module which you can install and run to demonstrate use of the JDatabase functionality for updating records in the database, and which you can adapt to experiment with some of the concepts described above. If you are unsure about development and installing a Joomla module then following the tutorial at [[S:MyLanguage/J3.x:Creating a simple module/Introduction| Creating a simple module ]] will help.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:45--&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Important note: In any Joomla extensions which you develop that you should avoid accessing the core Joomla tables directly like this and should instead use the Joomla APIs if at all possible, because the database structures may change without warning.&#039;&#039;&#039;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:46--&amp;gt;&lt;br /&gt;
In a folder mod_db_update create the following 2 files:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;mod_db_update.xml&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;extension type=&amp;quot;module&amp;quot; version=&amp;quot;3.1&amp;quot; client=&amp;quot;site&amp;quot; method=&amp;quot;upgrade&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;Database update demo&amp;lt;/name&amp;gt;&lt;br /&gt;
    &amp;lt;version&amp;gt;1.0.1&amp;lt;/version&amp;gt;&lt;br /&gt;
    &amp;lt;description&amp;gt;Code demonstrating use of Joomla Database class to perform SQL UPDATE statements&amp;lt;/description&amp;gt;&lt;br /&gt;
    &amp;lt;files&amp;gt;&lt;br /&gt;
        &amp;lt;filename module=&amp;quot;mod_db_update&amp;quot;&amp;gt;mod_db_update.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
    &amp;lt;/files&amp;gt;&lt;br /&gt;
&amp;lt;/extension&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;mod_db_update.php&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die(&#039;Restricted Access&#039;);&lt;br /&gt;
&lt;br /&gt;
use Joomla\CMS\Factory;&lt;br /&gt;
&lt;br /&gt;
$db = Factory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$me = Factory::getUser();&lt;br /&gt;
&lt;br /&gt;
if ($me-&amp;gt;id == 0)&lt;br /&gt;
{&lt;br /&gt;
	echo &amp;quot;Not logged on!&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
	$email = $me-&amp;gt;email; &lt;br /&gt;
	// change the case of the email address&lt;br /&gt;
	$email_uppercase = strtoupper($email);&lt;br /&gt;
	if ($email == $email_uppercase)&lt;br /&gt;
	{&lt;br /&gt;
		$new_email = strtolower($email);&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		$new_email = $email_uppercase;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
	$fields = array($db-&amp;gt;quoteName(&#039;email&#039;) . &amp;quot; = &#039;{$new_email}&#039;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
	$conditions = array($db-&amp;gt;quoteName(&#039;id&#039;) . &#039; = &#039; . $me-&amp;gt;id); &lt;br /&gt;
&lt;br /&gt;
	$query-&amp;gt;update($db-&amp;gt;quoteName(&#039;#__users&#039;))-&amp;gt;set($fields)-&amp;gt;where($conditions);&lt;br /&gt;
&lt;br /&gt;
	echo $db-&amp;gt;replacePrefix((string) $query);&lt;br /&gt;
	&lt;br /&gt;
	$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
	if ($result = $db-&amp;gt;execute())&lt;br /&gt;
	{&lt;br /&gt;
		echo &amp;quot;Email case successfully changed!&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:47--&amp;gt;&lt;br /&gt;
The code above updates the email address field in the &amp;lt;tt&amp;gt;users&amp;lt;/tt&amp;gt; record of the currently logged-on user, toggling between upper case and lower case in successive reloads of the web page. &amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:48--&amp;gt;&lt;br /&gt;
The method &amp;lt;tt&amp;gt;Factory::getUser()&amp;lt;/tt&amp;gt; returns the &amp;lt;tt&amp;gt;user&amp;lt;/tt&amp;gt; object of the currently logged-on user, or if not logged on, then a blank &amp;lt;tt&amp;gt;user&amp;lt;/tt&amp;gt; object, whose &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt; field is set to zero. &amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:49--&amp;gt;&lt;br /&gt;
The &amp;lt;tt&amp;gt;$db-&amp;gt;replacePrefix((string) $query)&amp;lt;/tt&amp;gt; expression returns the actual SQL statement, and outputting this can be useful in debugging. &amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:50--&amp;gt;&lt;br /&gt;
Zip up the mod_db_update directory to create &amp;lt;tt&amp;gt;mod_db_update.zip&amp;lt;/tt&amp;gt;.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:51--&amp;gt;&lt;br /&gt;
Within your Joomla administrator go to Install Extensions and via the Upload Package File tab upload this zip file to install this sample log module.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:52--&amp;gt;&lt;br /&gt;
Make this module visible by editing it (click on it within the Modules page) then:&lt;br /&gt;
# making its status Published&lt;br /&gt;
# selecting a position on the page for it to be shown&lt;br /&gt;
# on the menu assignment tab specify the pages it should appear on&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:53--&amp;gt;&lt;br /&gt;
When you visit a site web page then you should see the module in your selected position, and it should output the SQL UPDATE statement and affirm that it has updated the record successfully. To confirm that it has updated the record correctly go into phpmyadmin and view the &amp;lt;tt&amp;gt;users&amp;lt;/tt&amp;gt; table within the Joomla database. The updates aren&#039;t visible via the admin Users functionality on the back end, as Joomla displays in lower case all the email addresses in the records. &amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:36--&amp;gt;&lt;br /&gt;
[[Category:Database]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=J3.x:Duplicate_usernames_cause_update_issue&amp;diff=661150</id>
		<title>J3.x:Duplicate usernames cause update issue</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=J3.x:Duplicate_usernames_cause_update_issue&amp;diff=661150"/>
		<updated>2020-04-11T16:45:54Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: note on how to remove all users who have never visited the site&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;&amp;lt;languages /&amp;gt;&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:1--&amp;gt; In some websites, updating to Joomla 3.9.16 results in a database error due to duplicated usernames. If this happens do not panic - the upgrade has been mostly completed without issue and is operating as usual, the remaining database change can be applied after following the instructions below.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==Errors reported== &amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:3--&amp;gt; Users receive an update error regarding a failed database query due to a duplicated key in their site&#039;s&amp;lt;/translate&amp;gt; &amp;lt;source lang=&amp;quot;sql&amp;quot; inline&amp;gt;#__users&amp;lt;/source&amp;gt; &amp;lt;translate&amp;gt;&amp;lt;!--T:4--&amp;gt; table when upgrading from Joomla 3.9.15 or older.&amp;lt;/translate&amp;gt;&lt;br /&gt;
[[File:76331128-c6389180-62ff-11ea-81d6-14cd3e5ab28d.png|thumb|Joomla 3.9.16 Upgrade Error]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==Versions affected== &amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
{{tip|&amp;lt;translate&amp;gt;&amp;lt;!--T:6--&amp;gt; This pertains only to Joomla! version(s):&amp;lt;/translate&amp;gt; &#039;&#039;&#039;3.9.16&#039;&#039;&#039;|title=&amp;lt;translate&amp;gt;&amp;lt;!--T:7--&amp;gt; General Information&amp;lt;/translate&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==What is the cause== &amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:9--&amp;gt; Your website has more than one user in the&amp;lt;/translate&amp;gt; &amp;lt;source lang=&amp;quot;sql&amp;quot; inline&amp;gt;#__users&amp;lt;/source&amp;gt; &amp;lt;translate&amp;gt;&amp;lt;!--T:10--&amp;gt; table with the same username, which is a security concern in that the incorrect account may be accessed by the wrong account owner.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==How to fix== &amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:12--&amp;gt; You will need to review your&amp;lt;/translate&amp;gt; &amp;lt;source lang=&amp;quot;sql&amp;quot; inline&amp;gt;#__users&amp;lt;/source&amp;gt; &amp;lt;translate&amp;gt;&amp;lt;!--T:13--&amp;gt; table in your database and fix any duplicated usernames by either removing old user accounts or changing the username until all usernames are unique. Once this is finished, if you have already upgraded to 3.9.16 run the database schema fixer tool to finish the upgrade (this step is not required if you do this review prior to upgrading).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:14--&amp;gt; Joomla is unable to automatically determine the correct action to take and as a result is unable to perform this step for you - it has to be fixed by you as the site owner.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:15--&amp;gt; The following SQL Query can be run on your database to view which usernames are duplicated. Replace the placeholder &amp;lt;code&amp;gt;#__&amp;lt;/code&amp;gt; with the table prefix of your Joomla database before you run it:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;sql&amp;quot; inline&amp;gt;SELECT username FROM #__users GROUP BY username HAVING COUNT(*) &amp;gt; 1&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;One possible way to make resolving this simpler might be to remove all users who have never visited the site.  Though this should be done with care, and ensure to backup the table first.  After running this query, you can check again how many duplicate users you have.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;sql&amp;quot; inline&amp;gt;DELETE FROM #__users WHERE lastvisitDate = &amp;quot;0000-00-00 00:00:00&amp;quot;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
[[Category:Version 3.9 FAQ{{#translation:}}]]&lt;br /&gt;
[[Category:Version 3.9.16 FAQ{{#translation:}}]]&lt;br /&gt;
[[Category:FAQ{{#translation:}}]]&lt;br /&gt;
[[Category:Joomla! 3.9{{#translation:}}]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=648442</id>
		<title>Selecting data using JDatabase</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=648442"/>
		<updated>2020-02-27T12:20:22Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: typo in example&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;&amp;lt;languages /&amp;gt;&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&amp;lt;noinclude&amp;gt;{{Joomla version|version=3.x}}{{Joomla version|version=2.5|status=eos}}&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
{{-}}&lt;br /&gt;
{{tip|&amp;lt;translate&amp;gt;&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
Note many examples online use &amp;lt;code&amp;gt;$db-&amp;gt;query()&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;$db-&amp;gt;execute()&amp;lt;/code&amp;gt;. This was the old method in Joomla 1.5 and 2.5 and will throw a deprecated notice in Joomla 3.0+.&amp;lt;/translate&amp;gt;|title=&amp;lt;translate&amp;gt;&amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
Version Note&amp;lt;/translate&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
This tutorial is split into two independent parts:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
* Inserting, updating and removing data from the database.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
* Selecting data from one or more tables and retrieving it in a variety of different forms&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
This section of the documentation looks at selecting data from a database table and retrieving it in a variety of formats. To see the other part [[S:MyLanguage/Inserting,_Updating_and_Removing_data_using_JDatabase|click here]]&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Introduction== &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
Joomla can use different kinds of SQL database systems and 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 you need just two 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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==The Query== &amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
Joomla&#039;s database querying changed with the introduction of Joomla 1.6. The recommended way of building database queries is through &amp;quot;query chaining&amp;quot; (although string queries are still supported).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source&#039;s query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer&#039;s source code.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code&amp;lt;/translate&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==Selecting Records from a Single Table== &amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
Below is an example of creating a database query using the &amp;lt;tt&amp;gt;JDatabaseQuery&amp;lt;/tt&amp;gt; class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)));&lt;br /&gt;
$query-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;));&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;custom.%&#039;));&lt;br /&gt;
$query-&amp;gt;order(&#039;ordering ASC&#039;);&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects (see later for more options on retrieving data).&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Here the &amp;lt;tt&amp;gt;quoteName()&amp;lt;/tt&amp;gt; function adds appropriate quotes around the column names to avoid conflicts with any database reserved word, now or in the future.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:19--&amp;gt;&lt;br /&gt;
The query can also be chained to simplify further:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;custom.%&#039;))&lt;br /&gt;
    -&amp;gt;order(&#039;ordering ASC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
Chaining method calls improves code readability and reduces code bloat as queries become longer and more complex.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
Grouping can be achieved simply too.  The following query would count the number of articles in each category.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array(&#039;catid&#039;, &#039;COUNT(*)&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;))&lt;br /&gt;
    -&amp;gt;group($db-&amp;gt;quoteName(&#039;catid&#039;));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
A limit can be set to a query using &amp;quot;setLimit&amp;quot;. For example in the following query, it would return up to 10 records.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;))&lt;br /&gt;
    -&amp;gt;setLimit(&#039;10&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Selecting Records from Multiple Tables== &amp;lt;!--T:23--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:24--&amp;gt;&lt;br /&gt;
Using the JDatabaseQuery&#039;s [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with &#039;a&#039;.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
// Note by putting &#039;a&#039; as a second parameter will generate `#__content` AS `a`&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;a%&#039;))&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects (see later for more options on retrieving data).&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for joins:&amp;lt;/translate&amp;gt;&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_innerJoin innerJoin()]&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_leftJoin leftJoin()]&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_rightJoin rightJoin()] &lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_outerJoin outerJoin()]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:26--&amp;gt;&lt;br /&gt;
We can use multiple joins to query across more than two tables:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;, &#039;c.*&#039;, &#039;d.*&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;LEFT&#039;, $db-&amp;gt;quoteName(&#039;#__user_profiles&#039;, &#039;c&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;c.user_id&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;RIGHT&#039;, $db-&amp;gt;quoteName(&#039;#__categories&#039;, &#039;d&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.catid&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;d.id&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;a%&#039;))&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:27--&amp;gt;&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:28--&amp;gt;&lt;br /&gt;
In some cases, you will also need to use the AS clause when selecting items to avoid column name conflicts. In this case, multiple select statements can be chained in conjunction with using the second parameter of $db-&amp;gt;quoteName.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(&#039;a.*&#039;)&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(&#039;b.username&#039;, &#039;username&#039;))&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(&#039;b.name&#039;, &#039;name&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;a%&#039;))&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:29--&amp;gt;&lt;br /&gt;
A second array can also be used as the second parameter of the select statement to populate the values of the AS clause. Remember to include nulls in the second array to correspond to columns in the first array that you don&#039;t want to use the AS clause for:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array(&#039;a.*&#039;))&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;b.username&#039;, &#039;b.name&#039;), array(&#039;username&#039;, &#039;name&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;a%&#039;))&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using OR in queries== &amp;lt;!--T:24--&amp;gt;&lt;br /&gt;
When using multiple WHERE clauses in your query, they will be treated as an AND.  &lt;br /&gt;
&lt;br /&gt;
So, for example, the query below will return results where the &#039;name&#039; field AND the &#039;state&#039; field match.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;COUNT(*)&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($value)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;state&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($state));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To use a WHERE clause as an OR, the query can be written like this&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;COUNT(*)&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($name_one), &#039;OR&#039;)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($name_two));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
it can also be written like this&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;COUNT(*)&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($name_one)&lt;br /&gt;
    -&amp;gt;orWhere($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($name_two));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Query Results == &amp;lt;!--T:30--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:31--&amp;gt;&lt;br /&gt;
The database class contains many methods for working with a query&#039;s result set.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Single Value Result === &amp;lt;!--T:32--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadResult() ==== &amp;lt;!--T:33--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:34--&amp;gt;&lt;br /&gt;
Use &#039;&#039;&#039;loadResult()&#039;&#039;&#039; when you expect just a single value back from your database query.&amp;lt;/translate&amp;gt; &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;
! &amp;lt;translate&amp;gt;&amp;lt;!--T:35--&amp;gt;&lt;br /&gt;
id&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:36--&amp;gt;&lt;br /&gt;
name&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:37--&amp;gt;&lt;br /&gt;
email&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:38--&amp;gt;&lt;br /&gt;
username&amp;lt;/translate&amp;gt;&lt;br /&gt;
|- &lt;br /&gt;
| 1 || style=&amp;quot;background:yellow&amp;quot; | John Smith || &amp;lt;translate&amp;gt;&amp;lt;!--T:39--&amp;gt;&lt;br /&gt;
johnsmith@domain.example&amp;lt;/translate&amp;gt; || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || &amp;lt;translate&amp;gt;&amp;lt;!--T:40--&amp;gt;&lt;br /&gt;
magda_h@domain.example&amp;lt;/translate&amp;gt; || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || &amp;lt;translate&amp;gt;&amp;lt;!--T:41--&amp;gt;&lt;br /&gt;
ydg@domain.example&amp;lt;/translate&amp;gt; || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:42--&amp;gt;&lt;br /&gt;
This is often the result of a &#039;count&#039; query to get a number of records:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;COUNT(*)&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($value));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:134--&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).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;field_name&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;some_name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($some_value));&lt;br /&gt;
&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;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Single Row Results === &amp;lt;!--T:43--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:44--&amp;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.&amp;lt;/translate&amp;gt;&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;
! &amp;lt;translate&amp;gt;&amp;lt;!--T:45--&amp;gt;&lt;br /&gt;
id&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:46--&amp;gt;&lt;br /&gt;
name&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:47--&amp;gt;&lt;br /&gt;
email&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:48--&amp;gt;&lt;br /&gt;
username&amp;lt;/translate&amp;gt;&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 1 || John Smith || &amp;lt;translate&amp;gt;&amp;lt;!--T:49--&amp;gt;&lt;br /&gt;
johnsmith@domain.example&amp;lt;/translate&amp;gt; || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || &amp;lt;translate&amp;gt;&amp;lt;!--T:50--&amp;gt;&lt;br /&gt;
magda_h@domain.example&amp;lt;/translate&amp;gt; || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || &amp;lt;translate&amp;gt;&amp;lt;!--T:51--&amp;gt;&lt;br /&gt;
ydg@domain.example&amp;lt;/translate&amp;gt; || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadRow() ==== &amp;lt;!--T:52--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:53--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadRow()&amp;lt;/tt&amp;gt; returns an indexed array from a single record in the table:&amp;lt;/translate&amp;gt; &lt;br /&gt;
&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:133--&amp;gt;&lt;br /&gt;
will give:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; 1, [1] =&amp;gt; John Smith, [2] =&amp;gt; johnsmith@domain.example, [3] =&amp;gt; johnsmith ) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:54--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:55--&amp;gt;&lt;br /&gt;
Notes:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:56--&amp;gt;&lt;br /&gt;
# The array indices are numeric starting from zero.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:57--&amp;gt;&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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadAssoc() ==== &amp;lt;!--T:58--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:59--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadAssoc()&amp;lt;/tt&amp;gt; returns an associated array from a single record in the table:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;loadAssoc();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:60--&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@domain.example, [username] =&amp;gt; johnsmith )&amp;lt;/pre&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:61--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;name&#039;] // e.g. $row[&#039;email&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:62--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadObject() ==== &amp;lt;!--T:63--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:64--&amp;gt;&lt;br /&gt;
loadObject returns a PHP object from a single record in the table:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:65--&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@domain.example, [username] =&amp;gt; johnsmith )&amp;lt;/pre&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:66--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$result-&amp;gt;index // e.g. $result-&amp;gt;email&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:67--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
===Single Column Results === &amp;lt;!--T:68--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:69--&amp;gt;&lt;br /&gt;
Each of these results functions will return a single column from the database.&amp;lt;/translate&amp;gt; &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;
! &amp;lt;translate&amp;gt;&amp;lt;!--T:70--&amp;gt;&lt;br /&gt;
id&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:71--&amp;gt;&lt;br /&gt;
name&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:72--&amp;gt;&lt;br /&gt;
email&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:73--&amp;gt;&lt;br /&gt;
username&amp;lt;/translate&amp;gt;&lt;br /&gt;
|- &lt;br /&gt;
| 1 || style=&amp;quot;background:yellow&amp;quot; | John Smith || &amp;lt;translate&amp;gt;&amp;lt;!--T:74--&amp;gt;&lt;br /&gt;
johnsmith@domain.example&amp;lt;/translate&amp;gt; || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || style=&amp;quot;background:yellow&amp;quot; | Magda Hellman || &amp;lt;translate&amp;gt;&amp;lt;!--T:75--&amp;gt;&lt;br /&gt;
magda_h@domain.example&amp;lt;/translate&amp;gt; || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || style=&amp;quot;background:yellow&amp;quot; | Yvonne de Gaulle || &amp;lt;translate&amp;gt;&amp;lt;!--T:76--&amp;gt;&lt;br /&gt;
ydg@domain.example&amp;lt;/translate&amp;gt; || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadColumn() ==== &amp;lt;!--T:77--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:78--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadColumn()&amp;lt;/tt&amp;gt; returns an indexed array from a single column in the table:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
$query-&amp;gt;select(&#039;name&#039;));&lt;br /&gt;
      -&amp;gt;from . . .&amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadColumn();&lt;br /&gt;
print_r($column);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:79--&amp;gt;&lt;br /&gt;
will give:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:80--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:81--&amp;gt;&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&lt;br /&gt;
# &amp;lt;tt&amp;gt;loadColumn()&amp;lt;/tt&amp;gt; is equivalent to loadColumn(0).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadColumn($index) ==== &amp;lt;!--T:82--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:83--&amp;gt;&lt;br /&gt;
loadColumn($index) returns an indexed array from a single column in the table:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
$query-&amp;gt;select(array(&#039;name&#039;, &#039;email&#039;, &#039;username&#039;));&lt;br /&gt;
      -&amp;gt;from . . .&amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadColumn(1);&lt;br /&gt;
print_r($column);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:84--&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; johnsmith@domain.example, [1] =&amp;gt; magda_h@domain.example, [2] =&amp;gt; ydg@domain.example )&amp;lt;/pre&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:85--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:86--&amp;gt;&lt;br /&gt;
loadColumn($index) allows you to iterate through a series of columns in the results&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;loadColumn($i);&lt;br /&gt;
  print_r($column);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:87--&amp;gt;&lt;br /&gt;
will give:&amp;lt;/translate&amp;gt;&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@domain.example, [1] =&amp;gt; magda_h@domain.example, [2] =&amp;gt; ydg@domain.example ),&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:88--&amp;gt;&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Multi-Row Results === &amp;lt;!--T:89--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:90--&amp;gt;&lt;br /&gt;
Each of these results functions will return multiple records from the database.&amp;lt;/translate&amp;gt; &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;
! &amp;lt;translate&amp;gt;&amp;lt;!--T:91--&amp;gt;&lt;br /&gt;
id&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:92--&amp;gt;&lt;br /&gt;
name&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:93--&amp;gt;&lt;br /&gt;
email&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:94--&amp;gt;&lt;br /&gt;
username&amp;lt;/translate&amp;gt;&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 1 || John Smith || johnsmith@domain.example || johnsmith&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadRowList() ==== &amp;lt;!--T:95--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:96--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadRowList()&amp;lt;/tt&amp;gt; returns an indexed array of indexed arrays from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:97--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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@domain.example, [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@domain.example, [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@domain.example, [3] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:98--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;index&#039;] // e.g. $row[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:99--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:100--&amp;gt;&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;==== loadAssocList() ==== &amp;lt;!--T:101--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:102--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadAssocList()&amp;lt;/tt&amp;gt; returns an indexed array of associated arrays from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:103--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&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@domain.example, [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@domain.example, [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@domain.example, [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:104--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;index&#039;] // e.g. $row[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:105--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;==== loadAssocList($key) ==== &amp;lt;!--T:106--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:107--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadAssocList(&#039;key&#039;)&amp;lt;/tt&amp;gt; returns an associated array - indexed on &#039;key&#039; - of associated arrays from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:108--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&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@domain.example, [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@domain.example, [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@domain.example, [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:109--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;key_value&#039;] // e.g. $row[&#039;johnsmith&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:110--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:111--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;==== loadAssocList($key, $column) ==== &amp;lt;!--T:112--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:113--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadAssocList(&#039;key&#039;, &#039;column&#039;)&amp;lt;/tt&amp;gt; returns an associative array, indexed on &#039;key&#039;, of values from the column named &#039;column&#039; returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;id&#039;, &#039;username&#039;);&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:114--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[1] =&amp;gt; John Smith, &lt;br /&gt;
[2] =&amp;gt; Magda Hellman, &lt;br /&gt;
[3] =&amp;gt; Yvonne de Gaulle,&lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:115--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;==== loadObjectList() ==== &amp;lt;!--T:116--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:117--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadObjectList()&amp;lt;/tt&amp;gt; returns an indexed array of PHP objects from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:118--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&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@domain.example, [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@domain.example, [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@domain.example, [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:119--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;index&#039;] // e.g. $row[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:120--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;==== loadObjectList($key) ==== &amp;lt;!--T:121--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:122--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadObjectList(&#039;key&#039;)&amp;lt;/tt&amp;gt; returns an associated array - indexed on &#039;key&#039; - of objects from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:123--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&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@domain.example, [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@domain.example, [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@domain.example, [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:124--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;key_value&#039;] // e.g. $row[&#039;johnsmith&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:125--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:126--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Miscellaneous Result Set Methods === &amp;lt;!--T:127--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== getNumRows() ==== &amp;lt;!--T:128--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:129--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;getNumRows()&amp;lt;/tt&amp;gt; will return the number of result rows found by the last SELECT or SHOW 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. To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or DELETE query, use getAffectedRows().&amp;lt;/translate&amp;gt;&lt;br /&gt;
 &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;execute();&lt;br /&gt;
$num_rows = $db-&amp;gt;getNumRows();&lt;br /&gt;
print_r($num_rows);&lt;br /&gt;
$result = $db-&amp;gt;loadRowList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:130--&amp;gt;&lt;br /&gt;
will return&amp;lt;/translate&amp;gt; &amp;lt;pre&amp;gt;3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:131--&amp;gt;&lt;br /&gt;
Note: getNumRows() is only valid for statements like SELECT or SHOW that return an actual result set. If you run getNumRows() after loadRowList() - or any other retrieval method - you will get a PHP Warning:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Warning: mysql_num_rows(): 80 is not a valid MySQL result resource &lt;br /&gt;
in libraries\joomla\database\database\mysql.php on line 344&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sample Module Code ==&lt;br /&gt;
&lt;br /&gt;
Below is the code for a simple Joomla module which you can install and run to demonstrate use of the JDatabase functionality, and which you can adapt to experiment with some of the concepts described above. If you are unsure about development and installing a Joomla module then following the tutorial at [[S:MyLanguage/J3.x:Creating a simple module/Introduction| Creating a simple module ]] will help.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important note: In any Joomla extensions which you develop that you should avoid accessing the core Joomla tables directly like this and should instead use the Joomla APIs if at all possible, because the database structures may change without warning.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In a folder mod_db_select create the following 2 files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;mod_db_select.xml&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;extension type=&amp;quot;module&amp;quot; version=&amp;quot;3.1&amp;quot; client=&amp;quot;site&amp;quot; method=&amp;quot;upgrade&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;Database select query demo&amp;lt;/name&amp;gt;&lt;br /&gt;
    &amp;lt;version&amp;gt;1.0.1&amp;lt;/version&amp;gt;&lt;br /&gt;
    &amp;lt;description&amp;gt;Code demonstrating use of Joomla Database class to perform SQL SELECT queries&amp;lt;/description&amp;gt;&lt;br /&gt;
    &amp;lt;files&amp;gt;&lt;br /&gt;
        &amp;lt;filename module=&amp;quot;mod_db_select&amp;quot;&amp;gt;mod_db_select.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
    &amp;lt;/files&amp;gt;&lt;br /&gt;
&amp;lt;/extension&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;mod_db_select.php&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die(&#039;Restricted Access&#039;);&lt;br /&gt;
&lt;br /&gt;
use Joomla\CMS\Factory;&lt;br /&gt;
&lt;br /&gt;
$db = Factory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$me = Factory::getUser();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;select($db-&amp;gt;quoteName(array(&#039;name&#039;, &#039;email&#039;)))&lt;br /&gt;
	-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__users&#039;))&lt;br /&gt;
	-&amp;gt;where($db-&amp;gt;quoteName(&#039;id&#039;) . &#039; != &#039; . $db-&amp;gt;quote($me-&amp;gt;id))&lt;br /&gt;
	-&amp;gt;order($db-&amp;gt;quoteName(&#039;name&#039;) . &#039; ASC&#039;);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
echo $db-&amp;gt;replacePrefix((string) $query);&lt;br /&gt;
&lt;br /&gt;
$results = $db-&amp;gt;loadAssocList();&lt;br /&gt;
&lt;br /&gt;
foreach ($results as $row) {&lt;br /&gt;
	echo &amp;quot;&amp;lt;p&amp;gt;&amp;quot; . $row[&#039;name&#039;] . &amp;quot;, &amp;quot; . $row[&#039;email&#039;] . &amp;quot;&amp;lt;br&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code above selects and outputs the username and email of the records in the Joomla &amp;lt;tt&amp;gt;users&amp;lt;/tt&amp;gt; table, apart from those of the currently logged-on user. The method &amp;lt;tt&amp;gt;Factory::getUser()&amp;lt;/tt&amp;gt; returns the &amp;lt;tt&amp;gt;user&amp;lt;/tt&amp;gt; object of the currently logged-on user, or if not logged on, then a blank &amp;lt;tt&amp;gt;user&amp;lt;/tt&amp;gt; object, whose &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt; field is set to zero. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;$db-&amp;gt;replacePrefix((string) $query)&amp;lt;/tt&amp;gt; expression returns the actual SQL statement, and outputting this can be useful in debugging. &lt;br /&gt;
&lt;br /&gt;
Zip up the mod_db_select directory to create &amp;lt;tt&amp;gt;mod_db_select.zip&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Within your Joomla administrator go to Install Extensions and via the Upload Package File tab select this zip file to install this sample log module.&lt;br /&gt;
&lt;br /&gt;
Make this module visible by editing it (click on it within the Modules page) then:&lt;br /&gt;
# making its status Published&lt;br /&gt;
# selecting a position on the page for it to be shown&lt;br /&gt;
# on the menu assignment tab specify the pages it should appear on&lt;br /&gt;
&lt;br /&gt;
When you visit a site web page then you should see the module in your selected position, and it should output the SQL SELECT statement and the sequence of name, email values from the Joomla users table. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== See also == &amp;lt;!--T:135--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
*[[S:MyLanguage/Inserting, Updating and Removing data using JDatabase|&amp;lt;translate&amp;gt;&amp;lt;!--T:136--&amp;gt; Inserting, Updating and Removing data using JDatabase&amp;lt;/translate&amp;gt;]]&lt;br /&gt;
*[[S:MyLanguage/Using the union methods in database queries|&amp;lt;translate&amp;gt;&amp;lt;!--T:137--&amp;gt; Using the union methods in database queries&amp;lt;/translate&amp;gt;]] &amp;lt;translate&amp;gt;&amp;lt;!--T:138--&amp;gt; (Joomla! 3.3+)&amp;lt;/translate&amp;gt;&lt;br /&gt;
*[https://api.joomla.org/cms-3/classes/JDatabaseQuery.html &amp;lt;translate&amp;gt;&amp;lt;!--T:139--&amp;gt; Joomla CMS 3.8 API&amp;lt;/translate&amp;gt;] &lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
[[Category:Database{{#translation:}}]]&lt;br /&gt;
[[Category:JFactory{{#translation:}}]]&lt;br /&gt;
[[Category:Extension development{{#translation:}}]]&lt;br /&gt;
[[Category:Development Recommended Reading{{#translation:}}]]&lt;br /&gt;
[[Category:Tutorials{{#translation:}}]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=648441</id>
		<title>Selecting data using JDatabase</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=648441"/>
		<updated>2020-02-27T12:18:38Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: adding OR clause info&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;&amp;lt;languages /&amp;gt;&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&amp;lt;noinclude&amp;gt;{{Joomla version|version=3.x}}{{Joomla version|version=2.5|status=eos}}&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
{{-}}&lt;br /&gt;
{{tip|&amp;lt;translate&amp;gt;&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
Note many examples online use &amp;lt;code&amp;gt;$db-&amp;gt;query()&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;$db-&amp;gt;execute()&amp;lt;/code&amp;gt;. This was the old method in Joomla 1.5 and 2.5 and will throw a deprecated notice in Joomla 3.0+.&amp;lt;/translate&amp;gt;|title=&amp;lt;translate&amp;gt;&amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
Version Note&amp;lt;/translate&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
This tutorial is split into two independent parts:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
* Inserting, updating and removing data from the database.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
* Selecting data from one or more tables and retrieving it in a variety of different forms&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
This section of the documentation looks at selecting data from a database table and retrieving it in a variety of formats. To see the other part [[S:MyLanguage/Inserting,_Updating_and_Removing_data_using_JDatabase|click here]]&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Introduction== &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
Joomla can use different kinds of SQL database systems and 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 you need just two 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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==The Query== &amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
Joomla&#039;s database querying changed with the introduction of Joomla 1.6. The recommended way of building database queries is through &amp;quot;query chaining&amp;quot; (although string queries are still supported).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source&#039;s query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer&#039;s source code.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code&amp;lt;/translate&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==Selecting Records from a Single Table== &amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
Below is an example of creating a database query using the &amp;lt;tt&amp;gt;JDatabaseQuery&amp;lt;/tt&amp;gt; class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)));&lt;br /&gt;
$query-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;));&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;custom.%&#039;));&lt;br /&gt;
$query-&amp;gt;order(&#039;ordering ASC&#039;);&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects (see later for more options on retrieving data).&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Here the &amp;lt;tt&amp;gt;quoteName()&amp;lt;/tt&amp;gt; function adds appropriate quotes around the column names to avoid conflicts with any database reserved word, now or in the future.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:19--&amp;gt;&lt;br /&gt;
The query can also be chained to simplify further:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;custom.%&#039;))&lt;br /&gt;
    -&amp;gt;order(&#039;ordering ASC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
Chaining method calls improves code readability and reduces code bloat as queries become longer and more complex.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
Grouping can be achieved simply too.  The following query would count the number of articles in each category.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array(&#039;catid&#039;, &#039;COUNT(*)&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;))&lt;br /&gt;
    -&amp;gt;group($db-&amp;gt;quoteName(&#039;catid&#039;));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
A limit can be set to a query using &amp;quot;setLimit&amp;quot;. For example in the following query, it would return up to 10 records.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;))&lt;br /&gt;
    -&amp;gt;setLimit(&#039;10&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Selecting Records from Multiple Tables== &amp;lt;!--T:23--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:24--&amp;gt;&lt;br /&gt;
Using the JDatabaseQuery&#039;s [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with &#039;a&#039;.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
// Note by putting &#039;a&#039; as a second parameter will generate `#__content` AS `a`&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;a%&#039;))&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects (see later for more options on retrieving data).&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for joins:&amp;lt;/translate&amp;gt;&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_innerJoin innerJoin()]&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_leftJoin leftJoin()]&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_rightJoin rightJoin()] &lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_outerJoin outerJoin()]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:26--&amp;gt;&lt;br /&gt;
We can use multiple joins to query across more than two tables:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;, &#039;c.*&#039;, &#039;d.*&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;LEFT&#039;, $db-&amp;gt;quoteName(&#039;#__user_profiles&#039;, &#039;c&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;c.user_id&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;RIGHT&#039;, $db-&amp;gt;quoteName(&#039;#__categories&#039;, &#039;d&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.catid&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;d.id&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;a%&#039;))&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:27--&amp;gt;&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:28--&amp;gt;&lt;br /&gt;
In some cases, you will also need to use the AS clause when selecting items to avoid column name conflicts. In this case, multiple select statements can be chained in conjunction with using the second parameter of $db-&amp;gt;quoteName.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(&#039;a.*&#039;)&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(&#039;b.username&#039;, &#039;username&#039;))&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(&#039;b.name&#039;, &#039;name&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;a%&#039;))&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:29--&amp;gt;&lt;br /&gt;
A second array can also be used as the second parameter of the select statement to populate the values of the AS clause. Remember to include nulls in the second array to correspond to columns in the first array that you don&#039;t want to use the AS clause for:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array(&#039;a.*&#039;))&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;b.username&#039;, &#039;b.name&#039;), array(&#039;username&#039;, &#039;name&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON &#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE &#039; . $db-&amp;gt;quote(&#039;a%&#039;))&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using OR in queries== &amp;lt;!--T:24--&amp;gt;&lt;br /&gt;
When using multiple WHERE clauses in your query, they will be treated as an AND.  &lt;br /&gt;
&lt;br /&gt;
So, for example, the query below will return results where the &#039;name&#039; field AND the &#039;state&#039; field match.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;COUNT(*)&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($value)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;state&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($state));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To use a WHERE clause as an OR, the query can be written like this&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;COUNT(*)&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($name_one)&#039;, &#039;OR&#039;)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($name_two));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
it can also be written like this&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;COUNT(*)&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($name_one)&lt;br /&gt;
    -&amp;gt;orWhere($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($name_two));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Query Results == &amp;lt;!--T:30--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:31--&amp;gt;&lt;br /&gt;
The database class contains many methods for working with a query&#039;s result set.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Single Value Result === &amp;lt;!--T:32--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadResult() ==== &amp;lt;!--T:33--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:34--&amp;gt;&lt;br /&gt;
Use &#039;&#039;&#039;loadResult()&#039;&#039;&#039; when you expect just a single value back from your database query.&amp;lt;/translate&amp;gt; &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;
! &amp;lt;translate&amp;gt;&amp;lt;!--T:35--&amp;gt;&lt;br /&gt;
id&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:36--&amp;gt;&lt;br /&gt;
name&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:37--&amp;gt;&lt;br /&gt;
email&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:38--&amp;gt;&lt;br /&gt;
username&amp;lt;/translate&amp;gt;&lt;br /&gt;
|- &lt;br /&gt;
| 1 || style=&amp;quot;background:yellow&amp;quot; | John Smith || &amp;lt;translate&amp;gt;&amp;lt;!--T:39--&amp;gt;&lt;br /&gt;
johnsmith@domain.example&amp;lt;/translate&amp;gt; || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || &amp;lt;translate&amp;gt;&amp;lt;!--T:40--&amp;gt;&lt;br /&gt;
magda_h@domain.example&amp;lt;/translate&amp;gt; || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || &amp;lt;translate&amp;gt;&amp;lt;!--T:41--&amp;gt;&lt;br /&gt;
ydg@domain.example&amp;lt;/translate&amp;gt; || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:42--&amp;gt;&lt;br /&gt;
This is often the result of a &#039;count&#039; query to get a number of records:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;COUNT(*)&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($value));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:134--&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).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
$query = $db&lt;br /&gt;
    -&amp;gt;getQuery(true)&lt;br /&gt;
    -&amp;gt;select(&#039;field_name&#039;)&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;some_name&#039;) . &amp;quot; = &amp;quot; . $db-&amp;gt;quote($some_value));&lt;br /&gt;
&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;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Single Row Results === &amp;lt;!--T:43--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:44--&amp;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.&amp;lt;/translate&amp;gt;&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;
! &amp;lt;translate&amp;gt;&amp;lt;!--T:45--&amp;gt;&lt;br /&gt;
id&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:46--&amp;gt;&lt;br /&gt;
name&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:47--&amp;gt;&lt;br /&gt;
email&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:48--&amp;gt;&lt;br /&gt;
username&amp;lt;/translate&amp;gt;&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 1 || John Smith || &amp;lt;translate&amp;gt;&amp;lt;!--T:49--&amp;gt;&lt;br /&gt;
johnsmith@domain.example&amp;lt;/translate&amp;gt; || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || &amp;lt;translate&amp;gt;&amp;lt;!--T:50--&amp;gt;&lt;br /&gt;
magda_h@domain.example&amp;lt;/translate&amp;gt; || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || &amp;lt;translate&amp;gt;&amp;lt;!--T:51--&amp;gt;&lt;br /&gt;
ydg@domain.example&amp;lt;/translate&amp;gt; || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadRow() ==== &amp;lt;!--T:52--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:53--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadRow()&amp;lt;/tt&amp;gt; returns an indexed array from a single record in the table:&amp;lt;/translate&amp;gt; &lt;br /&gt;
&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:133--&amp;gt;&lt;br /&gt;
will give:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; 1, [1] =&amp;gt; John Smith, [2] =&amp;gt; johnsmith@domain.example, [3] =&amp;gt; johnsmith ) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:54--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:55--&amp;gt;&lt;br /&gt;
Notes:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:56--&amp;gt;&lt;br /&gt;
# The array indices are numeric starting from zero.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:57--&amp;gt;&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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadAssoc() ==== &amp;lt;!--T:58--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:59--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadAssoc()&amp;lt;/tt&amp;gt; returns an associated array from a single record in the table:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;loadAssoc();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:60--&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@domain.example, [username] =&amp;gt; johnsmith )&amp;lt;/pre&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:61--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;name&#039;] // e.g. $row[&#039;email&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:62--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadObject() ==== &amp;lt;!--T:63--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:64--&amp;gt;&lt;br /&gt;
loadObject returns a PHP object from a single record in the table:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:65--&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@domain.example, [username] =&amp;gt; johnsmith )&amp;lt;/pre&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:66--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$result-&amp;gt;index // e.g. $result-&amp;gt;email&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:67--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
===Single Column Results === &amp;lt;!--T:68--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:69--&amp;gt;&lt;br /&gt;
Each of these results functions will return a single column from the database.&amp;lt;/translate&amp;gt; &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;
! &amp;lt;translate&amp;gt;&amp;lt;!--T:70--&amp;gt;&lt;br /&gt;
id&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:71--&amp;gt;&lt;br /&gt;
name&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:72--&amp;gt;&lt;br /&gt;
email&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:73--&amp;gt;&lt;br /&gt;
username&amp;lt;/translate&amp;gt;&lt;br /&gt;
|- &lt;br /&gt;
| 1 || style=&amp;quot;background:yellow&amp;quot; | John Smith || &amp;lt;translate&amp;gt;&amp;lt;!--T:74--&amp;gt;&lt;br /&gt;
johnsmith@domain.example&amp;lt;/translate&amp;gt; || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || style=&amp;quot;background:yellow&amp;quot; | Magda Hellman || &amp;lt;translate&amp;gt;&amp;lt;!--T:75--&amp;gt;&lt;br /&gt;
magda_h@domain.example&amp;lt;/translate&amp;gt; || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || style=&amp;quot;background:yellow&amp;quot; | Yvonne de Gaulle || &amp;lt;translate&amp;gt;&amp;lt;!--T:76--&amp;gt;&lt;br /&gt;
ydg@domain.example&amp;lt;/translate&amp;gt; || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadColumn() ==== &amp;lt;!--T:77--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:78--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadColumn()&amp;lt;/tt&amp;gt; returns an indexed array from a single column in the table:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
$query-&amp;gt;select(&#039;name&#039;));&lt;br /&gt;
      -&amp;gt;from . . .&amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadColumn();&lt;br /&gt;
print_r($column);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:79--&amp;gt;&lt;br /&gt;
will give:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:80--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:81--&amp;gt;&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&lt;br /&gt;
# &amp;lt;tt&amp;gt;loadColumn()&amp;lt;/tt&amp;gt; is equivalent to loadColumn(0).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadColumn($index) ==== &amp;lt;!--T:82--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:83--&amp;gt;&lt;br /&gt;
loadColumn($index) returns an indexed array from a single column in the table:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;&amp;gt;&lt;br /&gt;
$query-&amp;gt;select(array(&#039;name&#039;, &#039;email&#039;, &#039;username&#039;));&lt;br /&gt;
      -&amp;gt;from . . .&amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadColumn(1);&lt;br /&gt;
print_r($column);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:84--&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; johnsmith@domain.example, [1] =&amp;gt; magda_h@domain.example, [2] =&amp;gt; ydg@domain.example )&amp;lt;/pre&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:85--&amp;gt;&lt;br /&gt;
You can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:86--&amp;gt;&lt;br /&gt;
loadColumn($index) allows you to iterate through a series of columns in the results&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;loadColumn($i);&lt;br /&gt;
  print_r($column);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:87--&amp;gt;&lt;br /&gt;
will give:&amp;lt;/translate&amp;gt;&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@domain.example, [1] =&amp;gt; magda_h@domain.example, [2] =&amp;gt; ydg@domain.example ),&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:88--&amp;gt;&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Multi-Row Results === &amp;lt;!--T:89--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:90--&amp;gt;&lt;br /&gt;
Each of these results functions will return multiple records from the database.&amp;lt;/translate&amp;gt; &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;
! &amp;lt;translate&amp;gt;&amp;lt;!--T:91--&amp;gt;&lt;br /&gt;
id&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:92--&amp;gt;&lt;br /&gt;
name&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:93--&amp;gt;&lt;br /&gt;
email&amp;lt;/translate&amp;gt; !! &amp;lt;translate&amp;gt;&amp;lt;!--T:94--&amp;gt;&lt;br /&gt;
username&amp;lt;/translate&amp;gt;&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 1 || John Smith || johnsmith@domain.example || johnsmith&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== loadRowList() ==== &amp;lt;!--T:95--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:96--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadRowList()&amp;lt;/tt&amp;gt; returns an indexed array of indexed arrays from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:97--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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@domain.example, [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@domain.example, [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@domain.example, [3] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:98--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;index&#039;] // e.g. $row[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:99--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:100--&amp;gt;&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;==== loadAssocList() ==== &amp;lt;!--T:101--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:102--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadAssocList()&amp;lt;/tt&amp;gt; returns an indexed array of associated arrays from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:103--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&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@domain.example, [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@domain.example, [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@domain.example, [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:104--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;index&#039;] // e.g. $row[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:105--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;==== loadAssocList($key) ==== &amp;lt;!--T:106--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:107--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadAssocList(&#039;key&#039;)&amp;lt;/tt&amp;gt; returns an associated array - indexed on &#039;key&#039; - of associated arrays from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:108--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&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@domain.example, [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@domain.example, [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@domain.example, [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:109--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;key_value&#039;] // e.g. $row[&#039;johnsmith&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:110--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:111--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;==== loadAssocList($key, $column) ==== &amp;lt;!--T:112--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:113--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadAssocList(&#039;key&#039;, &#039;column&#039;)&amp;lt;/tt&amp;gt; returns an associative array, indexed on &#039;key&#039;, of values from the column named &#039;column&#039; returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;id&#039;, &#039;username&#039;);&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:114--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[1] =&amp;gt; John Smith, &lt;br /&gt;
[2] =&amp;gt; Magda Hellman, &lt;br /&gt;
[3] =&amp;gt; Yvonne de Gaulle,&lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:115--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;==== loadObjectList() ==== &amp;lt;!--T:116--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:117--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadObjectList()&amp;lt;/tt&amp;gt; returns an indexed array of PHP objects from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:118--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&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@domain.example, [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@domain.example, [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@domain.example, [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:119--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;index&#039;] // e.g. $row[&#039;2&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:120--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;==== loadObjectList($key) ==== &amp;lt;!--T:121--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:122--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;loadObjectList(&#039;key&#039;)&amp;lt;/tt&amp;gt; returns an associated array - indexed on &#039;key&#039; - of objects from the table records returned by the query:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&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;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:123--&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&amp;lt;/translate&amp;gt;&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@domain.example, [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@domain.example, [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@domain.example, [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:124--&amp;gt;&lt;br /&gt;
You can access the individual rows by using:&amp;lt;/translate&amp;gt;&amp;lt;pre&amp;gt;$row[&#039;key_value&#039;] // e.g. $row[&#039;johnsmith&#039;]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:125--&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;/translate&amp;gt;&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;
&amp;lt;translate&amp;gt;&amp;lt;!--T:126--&amp;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.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Miscellaneous Result Set Methods === &amp;lt;!--T:127--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== getNumRows() ==== &amp;lt;!--T:128--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:129--&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;getNumRows()&amp;lt;/tt&amp;gt; will return the number of result rows found by the last SELECT or SHOW 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. To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or DELETE query, use getAffectedRows().&amp;lt;/translate&amp;gt;&lt;br /&gt;
 &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;execute();&lt;br /&gt;
$num_rows = $db-&amp;gt;getNumRows();&lt;br /&gt;
print_r($num_rows);&lt;br /&gt;
$result = $db-&amp;gt;loadRowList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:130--&amp;gt;&lt;br /&gt;
will return&amp;lt;/translate&amp;gt; &amp;lt;pre&amp;gt;3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:131--&amp;gt;&lt;br /&gt;
Note: getNumRows() is only valid for statements like SELECT or SHOW that return an actual result set. If you run getNumRows() after loadRowList() - or any other retrieval method - you will get a PHP Warning:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;Warning: mysql_num_rows(): 80 is not a valid MySQL result resource &lt;br /&gt;
in libraries\joomla\database\database\mysql.php on line 344&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sample Module Code ==&lt;br /&gt;
&lt;br /&gt;
Below is the code for a simple Joomla module which you can install and run to demonstrate use of the JDatabase functionality, and which you can adapt to experiment with some of the concepts described above. If you are unsure about development and installing a Joomla module then following the tutorial at [[S:MyLanguage/J3.x:Creating a simple module/Introduction| Creating a simple module ]] will help.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important note: In any Joomla extensions which you develop that you should avoid accessing the core Joomla tables directly like this and should instead use the Joomla APIs if at all possible, because the database structures may change without warning.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In a folder mod_db_select create the following 2 files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;mod_db_select.xml&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;extension type=&amp;quot;module&amp;quot; version=&amp;quot;3.1&amp;quot; client=&amp;quot;site&amp;quot; method=&amp;quot;upgrade&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;Database select query demo&amp;lt;/name&amp;gt;&lt;br /&gt;
    &amp;lt;version&amp;gt;1.0.1&amp;lt;/version&amp;gt;&lt;br /&gt;
    &amp;lt;description&amp;gt;Code demonstrating use of Joomla Database class to perform SQL SELECT queries&amp;lt;/description&amp;gt;&lt;br /&gt;
    &amp;lt;files&amp;gt;&lt;br /&gt;
        &amp;lt;filename module=&amp;quot;mod_db_select&amp;quot;&amp;gt;mod_db_select.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
    &amp;lt;/files&amp;gt;&lt;br /&gt;
&amp;lt;/extension&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;mod_db_select.php&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die(&#039;Restricted Access&#039;);&lt;br /&gt;
&lt;br /&gt;
use Joomla\CMS\Factory;&lt;br /&gt;
&lt;br /&gt;
$db = Factory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$me = Factory::getUser();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;select($db-&amp;gt;quoteName(array(&#039;name&#039;, &#039;email&#039;)))&lt;br /&gt;
	-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__users&#039;))&lt;br /&gt;
	-&amp;gt;where($db-&amp;gt;quoteName(&#039;id&#039;) . &#039; != &#039; . $db-&amp;gt;quote($me-&amp;gt;id))&lt;br /&gt;
	-&amp;gt;order($db-&amp;gt;quoteName(&#039;name&#039;) . &#039; ASC&#039;);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
echo $db-&amp;gt;replacePrefix((string) $query);&lt;br /&gt;
&lt;br /&gt;
$results = $db-&amp;gt;loadAssocList();&lt;br /&gt;
&lt;br /&gt;
foreach ($results as $row) {&lt;br /&gt;
	echo &amp;quot;&amp;lt;p&amp;gt;&amp;quot; . $row[&#039;name&#039;] . &amp;quot;, &amp;quot; . $row[&#039;email&#039;] . &amp;quot;&amp;lt;br&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code above selects and outputs the username and email of the records in the Joomla &amp;lt;tt&amp;gt;users&amp;lt;/tt&amp;gt; table, apart from those of the currently logged-on user. The method &amp;lt;tt&amp;gt;Factory::getUser()&amp;lt;/tt&amp;gt; returns the &amp;lt;tt&amp;gt;user&amp;lt;/tt&amp;gt; object of the currently logged-on user, or if not logged on, then a blank &amp;lt;tt&amp;gt;user&amp;lt;/tt&amp;gt; object, whose &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt; field is set to zero. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;$db-&amp;gt;replacePrefix((string) $query)&amp;lt;/tt&amp;gt; expression returns the actual SQL statement, and outputting this can be useful in debugging. &lt;br /&gt;
&lt;br /&gt;
Zip up the mod_db_select directory to create &amp;lt;tt&amp;gt;mod_db_select.zip&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Within your Joomla administrator go to Install Extensions and via the Upload Package File tab select this zip file to install this sample log module.&lt;br /&gt;
&lt;br /&gt;
Make this module visible by editing it (click on it within the Modules page) then:&lt;br /&gt;
# making its status Published&lt;br /&gt;
# selecting a position on the page for it to be shown&lt;br /&gt;
# on the menu assignment tab specify the pages it should appear on&lt;br /&gt;
&lt;br /&gt;
When you visit a site web page then you should see the module in your selected position, and it should output the SQL SELECT statement and the sequence of name, email values from the Joomla users table. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== See also == &amp;lt;!--T:135--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
*[[S:MyLanguage/Inserting, Updating and Removing data using JDatabase|&amp;lt;translate&amp;gt;&amp;lt;!--T:136--&amp;gt; Inserting, Updating and Removing data using JDatabase&amp;lt;/translate&amp;gt;]]&lt;br /&gt;
*[[S:MyLanguage/Using the union methods in database queries|&amp;lt;translate&amp;gt;&amp;lt;!--T:137--&amp;gt; Using the union methods in database queries&amp;lt;/translate&amp;gt;]] &amp;lt;translate&amp;gt;&amp;lt;!--T:138--&amp;gt; (Joomla! 3.3+)&amp;lt;/translate&amp;gt;&lt;br /&gt;
*[https://api.joomla.org/cms-3/classes/JDatabaseQuery.html &amp;lt;translate&amp;gt;&amp;lt;!--T:139--&amp;gt; Joomla CMS 3.8 API&amp;lt;/translate&amp;gt;] &lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
[[Category:Database{{#translation:}}]]&lt;br /&gt;
[[Category:JFactory{{#translation:}}]]&lt;br /&gt;
[[Category:Extension development{{#translation:}}]]&lt;br /&gt;
[[Category:Development Recommended Reading{{#translation:}}]]&lt;br /&gt;
[[Category:Tutorials{{#translation:}}]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=File_form_field_type&amp;diff=645585</id>
		<title>File form field type</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=File_form_field_type&amp;diff=645585"/>
		<updated>2020-01-21T15:07:09Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: mozilla link rather than w3 schools, better docs&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;&amp;lt;languages /&amp;gt;&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
Provides an input field for files&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;type&#039;&#039;&#039; (mandatory) must be &#039;&#039;file&#039;&#039;.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;name&#039;&#039;&#039; (mandatory) is the unique name of the field.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;label&#039;&#039;&#039; (mandatory) (translatable) is the descriptive title of the field.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;description&#039;&#039;&#039; (optional) (translatable) is text that will be shown as a tooltip when the user moves the mouse over the drop-down box.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;default&#039;&#039;&#039; (optional) (not translatable) is the default value, but doesn&#039;t mean much for a file.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;size&#039;&#039;&#039; (optional) is the width of the file box in characters.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
* [https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file &#039;&#039;&#039;accept&#039;&#039;&#039;] (optional) Tells the browser what MIME types your form will allow to be uploaded.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;class&#039;&#039;&#039; (optional) is a CSS class name for the HTML form field.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;labelclass&#039;&#039;&#039; (optional) adds a CSS class for form field&#039;s label; for Joomla 2.5.4+&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;disabled&#039;&#039;&#039; (optional)  HTML equivalent attribute&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;onchange&#039;&#039;&#039; (optional)  HTML equivalent attribute (javascript use)&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;required&#039;&#039;&#039; Cannot be used with this field type.  If the field is marked as required it will &#039;&#039;&#039;always&#039;&#039;&#039; fail validation regardless of whether a file has been uploaded or not.  The suggested workaround is to add a &#039;&#039;&#039;filerequired&#039;&#039;&#039; attribute which can be tested in your own file handling code.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;validate&#039;&#039;&#039; (optional)  Whether to Joomla validate the field according to rules&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;showon&#039;&#039;&#039; (optional)  Allows you to hide the field based on the value(s) of another field; for Joomla 3.2.4+&amp;lt;/translate&amp;gt;&lt;br /&gt;
* &amp;lt;translate&amp;gt;&amp;lt;!--T:22--&amp;gt; &#039;&#039;&#039;multiple&#039;&#039;&#039; (optional) Allows you to upload multiple files at once when set to multiple=&amp;quot;true&amp;quot;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;&lt;br /&gt;
When using the file input type you should always add the attribute enctype=&amp;quot;multipart/form-data&amp;quot; to your form tag. Otherwise, the uploaded files will not be attached correctly.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note 2:&#039;&#039;&#039;&lt;br /&gt;
You can put a soft limit file size by adding a hidden field with name=&amp;quot;MAX_FILE_SIZE&amp;quot; and value the maximum allowed bytes which is handled by php, but you must also handle it in your code with or without it.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
Example XML field definition:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;field name=&amp;quot;myfilevalue&amp;quot; type=&amp;quot;file&amp;quot; label=&amp;quot;Enter some text&amp;quot; description=&amp;quot;Choose an image from your computer with maximum 100KB&amp;quot; size=&amp;quot;10&amp;quot; accept=&amp;quot;image/*&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;=== See also === &amp;lt;!--T:18--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:19--&amp;gt;&lt;br /&gt;
* [[S:MyLanguage/Standard form field types|List of standard form field types]]&lt;br /&gt;
* [[S:MyLanguage/How_to_use_the_filesystem_package|How to use the filesystem package]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
[[Category:Standard form field types]]&lt;br /&gt;
[[Category:Form fields]]&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Accessing_the_current_user_object&amp;diff=618778</id>
		<title>Accessing the current user object</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Accessing_the_current_user_object&amp;diff=618778"/>
		<updated>2019-07-14T13:05:06Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: /* Determining Status */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{version/tutor|2.5,3.x}}&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
For every request in Joomla!, there is one user. Information about this user is readily available through the Joomla! framework in the form of an object. To get this object for the current user, use the following member function of JFactory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$user = JFactory::getUser();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or, to get information about any other registered user you can call the function with a user &#039;id&#039;, e.g. for user &#039;99&#039;;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$user = JFactory::getUser(99);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Getting a reference through getUser() ensures that only one user object is created during any one Joomla! request, saving on memory and processing time. Most of the information about the user is available through public member variables of the user object. This code displays the current user&#039;s name, email, user name and user type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot;&amp;lt;p&amp;gt;Your name is {$user-&amp;gt;name}, your email is {$user-&amp;gt;email}, and your username is {$user-&amp;gt;username}&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Since version 1.6 Joomla has a flexible ACL system, which makes $user-&amp;gt;usertype deprecated! &lt;br /&gt;
&lt;br /&gt;
The usertype field in #__users will only contain values for users that have been migrated from Joomla 1.5, but for new created users the field will be empty. &lt;br /&gt;
&lt;br /&gt;
Use $user-&amp;gt;groups to retrieve an array with all the IDs that refer to the groups (from #__usergroups table) of a user.&lt;br /&gt;
&lt;br /&gt;
== Object Member Variables and Parameters ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These are the relevant member variables automatically generated on a call to getUser():&lt;br /&gt;
* id - The unique, numerical user id. Use this when referencing the user record in other database tables.&lt;br /&gt;
* name - The name of the user. (e.g. Vint Cerf)&lt;br /&gt;
* username - The login/screen name of the user. (e.g. shmuffin1979)&lt;br /&gt;
* email - The email address of the user. (e.g. crashoverride@hackers.com)&lt;br /&gt;
* password - The encrypted version of the user&#039;s password&lt;br /&gt;
* password_clear - Set to the user&#039;s password only when it is being changed. Otherwise, remains blank.&lt;br /&gt;
* usertype - &amp;lt;strike&amp;gt;The role of the user within Joomla!. (Super Administrator, Editor, etc...)&amp;lt;/strike&amp;gt; Has been deprecated since Joomla 1.6. Use $user-&amp;gt;groups to retrieve an array with all the roles of a user.&lt;br /&gt;
* groups - Set to the user&#039;s group ids.&lt;br /&gt;
* block - Set to &#039;1&#039; when the user is set to &#039;blocked&#039; in Joomla!.&lt;br /&gt;
* registerDate - Set to the date when the user was first registered.&lt;br /&gt;
* lastvisitDate - Set to the date the user last visited the site.&lt;br /&gt;
* guest - If the user is not logged in, this variable will be set to &#039;1&#039;. The other variables will be unset or default values.&lt;br /&gt;
* lastResetTime - Set to the last time the password was reset.&lt;br /&gt;
* resetCount - Counts the number of password resets.&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
In addition to the member variables (which are stored in the database in columns), there are parameters for the user that hold preferences. To get one of these parameters, call the getParam() member function of the user object, passing in the name of the parameter you want along with a default value in case it is blank.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$user = JFactory::getUser();&lt;br /&gt;
$language = $user-&amp;gt;getParam(&#039;language&#039;, &#039;the default&#039;);&lt;br /&gt;
	&lt;br /&gt;
echo &amp;quot;&amp;lt;p&amp;gt;Your language is set to {$language}.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Determining Status ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Frequently, you will just want to make sure the user is logged in before continuing. The &#039;guest&#039; property will be set to &#039;1&#039; when the current user is not logged in. When the user is authenticated, &#039;guest&#039; will be set to &#039;0&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
	$user = JFactory::getUser();&lt;br /&gt;
	&lt;br /&gt;
	if ($user-&amp;gt;guest) {&lt;br /&gt;
		echo &amp;quot;&amp;lt;p&amp;gt;You must login to see the content. I want your email address.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
	} else {&lt;br /&gt;
		echo &amp;quot;&amp;lt;p&amp;gt;You are logged in, you can see the content.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Privileges ==&lt;br /&gt;
Not all users are given equal rights. For instance, a Super Administrator may be able to edit anyone&#039;s content, while a Publisher may only be able to edit their own. The authorise() member function can be used to determine if the current user has permission to do a certain task. The first parameter is used to identify which task we wish to check being allowed. The second represents the component we wish to retrieve the ACL information from.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
	$user = JFactory::getUser();&lt;br /&gt;
	&lt;br /&gt;
	if ($user-&amp;gt;authorise(&#039;core.edit&#039;, &#039;com_content&#039;))&lt;br /&gt;
	{&lt;br /&gt;
		echo &amp;quot;&amp;lt;p&amp;gt;You may edit all content.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		echo &amp;quot;&amp;lt;p&amp;gt;You may not edit all content.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	if ($user-&amp;gt;authorise(&#039;core.edit.own&#039;, &#039;com_content&#039;))&lt;br /&gt;
	{&lt;br /&gt;
		echo &amp;quot;&amp;lt;p&amp;gt;You may edit your own content.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		echo &amp;quot;&amp;lt;p&amp;gt;You may not edit your own content.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the current user is readily available in any part of your Joomla! extension. You need only fetch the object and access the member variables. You can authorise the user against the core permissions set, or create your own to suit your needs.&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
[https://api.joomla.org/cms-3/classes/Joomla.CMS.Factory.html#method_getUser Joomla 3.9 API reference] &lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Tutorials]][[Category:Framework]]&lt;br /&gt;
[[Category:Module Development]]&lt;br /&gt;
[[Category:Plugin Development]][[Category:Component Development]]&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Accessing_the_current_user_object&amp;diff=618777</id>
		<title>Accessing the current user object</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Accessing_the_current_user_object&amp;diff=618777"/>
		<updated>2019-07-14T13:04:33Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: /* Determining Status */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{version/tutor|2.5,3.x}}&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
For every request in Joomla!, there is one user. Information about this user is readily available through the Joomla! framework in the form of an object. To get this object for the current user, use the following member function of JFactory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$user = JFactory::getUser();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or, to get information about any other registered user you can call the function with a user &#039;id&#039;, e.g. for user &#039;99&#039;;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$user = JFactory::getUser(99);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Getting a reference through getUser() ensures that only one user object is created during any one Joomla! request, saving on memory and processing time. Most of the information about the user is available through public member variables of the user object. This code displays the current user&#039;s name, email, user name and user type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot;&amp;lt;p&amp;gt;Your name is {$user-&amp;gt;name}, your email is {$user-&amp;gt;email}, and your username is {$user-&amp;gt;username}&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Since version 1.6 Joomla has a flexible ACL system, which makes $user-&amp;gt;usertype deprecated! &lt;br /&gt;
&lt;br /&gt;
The usertype field in #__users will only contain values for users that have been migrated from Joomla 1.5, but for new created users the field will be empty. &lt;br /&gt;
&lt;br /&gt;
Use $user-&amp;gt;groups to retrieve an array with all the IDs that refer to the groups (from #__usergroups table) of a user.&lt;br /&gt;
&lt;br /&gt;
== Object Member Variables and Parameters ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These are the relevant member variables automatically generated on a call to getUser():&lt;br /&gt;
* id - The unique, numerical user id. Use this when referencing the user record in other database tables.&lt;br /&gt;
* name - The name of the user. (e.g. Vint Cerf)&lt;br /&gt;
* username - The login/screen name of the user. (e.g. shmuffin1979)&lt;br /&gt;
* email - The email address of the user. (e.g. crashoverride@hackers.com)&lt;br /&gt;
* password - The encrypted version of the user&#039;s password&lt;br /&gt;
* password_clear - Set to the user&#039;s password only when it is being changed. Otherwise, remains blank.&lt;br /&gt;
* usertype - &amp;lt;strike&amp;gt;The role of the user within Joomla!. (Super Administrator, Editor, etc...)&amp;lt;/strike&amp;gt; Has been deprecated since Joomla 1.6. Use $user-&amp;gt;groups to retrieve an array with all the roles of a user.&lt;br /&gt;
* groups - Set to the user&#039;s group ids.&lt;br /&gt;
* block - Set to &#039;1&#039; when the user is set to &#039;blocked&#039; in Joomla!.&lt;br /&gt;
* registerDate - Set to the date when the user was first registered.&lt;br /&gt;
* lastvisitDate - Set to the date the user last visited the site.&lt;br /&gt;
* guest - If the user is not logged in, this variable will be set to &#039;1&#039;. The other variables will be unset or default values.&lt;br /&gt;
* lastResetTime - Set to the last time the password was reset.&lt;br /&gt;
* resetCount - Counts the number of password resets.&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
In addition to the member variables (which are stored in the database in columns), there are parameters for the user that hold preferences. To get one of these parameters, call the getParam() member function of the user object, passing in the name of the parameter you want along with a default value in case it is blank.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$user = JFactory::getUser();&lt;br /&gt;
$language = $user-&amp;gt;getParam(&#039;language&#039;, &#039;the default&#039;);&lt;br /&gt;
	&lt;br /&gt;
echo &amp;quot;&amp;lt;p&amp;gt;Your language is set to {$language}.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Determining Status ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Frequently, you will just want to make sure the user is logged in before continuing. The &#039;guest&#039; property will be set to &#039;1&#039; when the current user is not logged in. When the user is authenticated, &#039;guest&#039; will be set to &#039;0&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
	$user = JFactory::getUser();&lt;br /&gt;
	&lt;br /&gt;
	if ($user-&amp;gt;guest) {&lt;br /&gt;
		echo &amp;quot;&amp;lt;p&amp;gt;You must login to see the content. I want your email address.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
	} else {&lt;br /&gt;
	        echo &amp;quot;&amp;lt;p&amp;gt;You are logged in, you can see the content.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Privileges ==&lt;br /&gt;
Not all users are given equal rights. For instance, a Super Administrator may be able to edit anyone&#039;s content, while a Publisher may only be able to edit their own. The authorise() member function can be used to determine if the current user has permission to do a certain task. The first parameter is used to identify which task we wish to check being allowed. The second represents the component we wish to retrieve the ACL information from.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
	$user = JFactory::getUser();&lt;br /&gt;
	&lt;br /&gt;
	if ($user-&amp;gt;authorise(&#039;core.edit&#039;, &#039;com_content&#039;))&lt;br /&gt;
	{&lt;br /&gt;
		echo &amp;quot;&amp;lt;p&amp;gt;You may edit all content.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		echo &amp;quot;&amp;lt;p&amp;gt;You may not edit all content.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	if ($user-&amp;gt;authorise(&#039;core.edit.own&#039;, &#039;com_content&#039;))&lt;br /&gt;
	{&lt;br /&gt;
		echo &amp;quot;&amp;lt;p&amp;gt;You may edit your own content.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		echo &amp;quot;&amp;lt;p&amp;gt;You may not edit your own content.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the current user is readily available in any part of your Joomla! extension. You need only fetch the object and access the member variables. You can authorise the user against the core permissions set, or create your own to suit your needs.&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
[https://api.joomla.org/cms-3/classes/Joomla.CMS.Factory.html#method_getUser Joomla 3.9 API reference] &lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Tutorials]][[Category:Framework]]&lt;br /&gt;
[[Category:Module Development]]&lt;br /&gt;
[[Category:Plugin Development]][[Category:Component Development]]&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Accessing_the_current_user_object&amp;diff=618776</id>
		<title>Accessing the current user object</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Accessing_the_current_user_object&amp;diff=618776"/>
		<updated>2019-07-14T13:03:25Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: /* Determining Status */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{version/tutor|2.5,3.x}}&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
For every request in Joomla!, there is one user. Information about this user is readily available through the Joomla! framework in the form of an object. To get this object for the current user, use the following member function of JFactory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$user = JFactory::getUser();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or, to get information about any other registered user you can call the function with a user &#039;id&#039;, e.g. for user &#039;99&#039;;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$user = JFactory::getUser(99);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Getting a reference through getUser() ensures that only one user object is created during any one Joomla! request, saving on memory and processing time. Most of the information about the user is available through public member variables of the user object. This code displays the current user&#039;s name, email, user name and user type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot;&amp;lt;p&amp;gt;Your name is {$user-&amp;gt;name}, your email is {$user-&amp;gt;email}, and your username is {$user-&amp;gt;username}&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Since version 1.6 Joomla has a flexible ACL system, which makes $user-&amp;gt;usertype deprecated! &lt;br /&gt;
&lt;br /&gt;
The usertype field in #__users will only contain values for users that have been migrated from Joomla 1.5, but for new created users the field will be empty. &lt;br /&gt;
&lt;br /&gt;
Use $user-&amp;gt;groups to retrieve an array with all the IDs that refer to the groups (from #__usergroups table) of a user.&lt;br /&gt;
&lt;br /&gt;
== Object Member Variables and Parameters ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These are the relevant member variables automatically generated on a call to getUser():&lt;br /&gt;
* id - The unique, numerical user id. Use this when referencing the user record in other database tables.&lt;br /&gt;
* name - The name of the user. (e.g. Vint Cerf)&lt;br /&gt;
* username - The login/screen name of the user. (e.g. shmuffin1979)&lt;br /&gt;
* email - The email address of the user. (e.g. crashoverride@hackers.com)&lt;br /&gt;
* password - The encrypted version of the user&#039;s password&lt;br /&gt;
* password_clear - Set to the user&#039;s password only when it is being changed. Otherwise, remains blank.&lt;br /&gt;
* usertype - &amp;lt;strike&amp;gt;The role of the user within Joomla!. (Super Administrator, Editor, etc...)&amp;lt;/strike&amp;gt; Has been deprecated since Joomla 1.6. Use $user-&amp;gt;groups to retrieve an array with all the roles of a user.&lt;br /&gt;
* groups - Set to the user&#039;s group ids.&lt;br /&gt;
* block - Set to &#039;1&#039; when the user is set to &#039;blocked&#039; in Joomla!.&lt;br /&gt;
* registerDate - Set to the date when the user was first registered.&lt;br /&gt;
* lastvisitDate - Set to the date the user last visited the site.&lt;br /&gt;
* guest - If the user is not logged in, this variable will be set to &#039;1&#039;. The other variables will be unset or default values.&lt;br /&gt;
* lastResetTime - Set to the last time the password was reset.&lt;br /&gt;
* resetCount - Counts the number of password resets.&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
In addition to the member variables (which are stored in the database in columns), there are parameters for the user that hold preferences. To get one of these parameters, call the getParam() member function of the user object, passing in the name of the parameter you want along with a default value in case it is blank.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$user = JFactory::getUser();&lt;br /&gt;
$language = $user-&amp;gt;getParam(&#039;language&#039;, &#039;the default&#039;);&lt;br /&gt;
	&lt;br /&gt;
echo &amp;quot;&amp;lt;p&amp;gt;Your language is set to {$language}.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Determining Status ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Frequently, you will just want to make sure the user is logged in before continuing. The &#039;guest&#039; property will be set to &#039;1&#039; when the current user is not logged in. When the user is authenticated, &#039;guest&#039; will be set to &#039;0&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
	$user = JFactory::getUser();&lt;br /&gt;
	&lt;br /&gt;
	if ($user-&amp;gt;guest) {&lt;br /&gt;
		echo &amp;quot;&amp;lt;p&amp;gt;You must login to see the content. I want your email address.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
	} else {&lt;br /&gt;
	        ?&amp;gt;&lt;br /&gt;
		&amp;lt;h1&amp;gt;Impromptu leftovers salad that goes well with fish&amp;lt;/h1&amp;gt;&lt;br /&gt;
		&amp;lt;ul&amp;gt;&lt;br /&gt;
			&amp;lt;li&amp;gt;1/2 cup chopped celery&amp;lt;/li&amp;gt;&lt;br /&gt;
			&amp;lt;li&amp;gt;1/4 cup raisins&amp;lt;/li&amp;gt;&lt;br /&gt;
			&amp;lt;li&amp;gt;1 teaspoon Extra Virgin Olive Oil&amp;lt;/li&amp;gt;&lt;br /&gt;
			&amp;lt;li&amp;gt;2 tablespoons of faux Thai lemongrass marinade&amp;lt;/li&amp;gt;&lt;br /&gt;
			&amp;lt;li&amp;gt;1/4 cup shredded fresh basil&amp;lt;/li&amp;gt;&lt;br /&gt;
			&amp;lt;li&amp;gt;Sprinkling of dill weed&amp;lt;/li&amp;gt;&lt;br /&gt;
			&amp;lt;li&amp;gt;Big pinch of kosher salt&amp;lt;/li&amp;gt;&lt;br /&gt;
			&amp;lt;li&amp;gt;Several lettuce leaves&amp;lt;/li&amp;gt;&lt;br /&gt;
		&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
			&amp;lt;p&amp;gt;Wash the lettuce and basil and place in a salad bowl.&lt;br /&gt;
			Get out a much smaller bowl and swish around all of the remaining ingredients. &lt;br /&gt;
			Pour this over the greens and toss.&lt;br /&gt;
			Serves two.&amp;lt;/p&amp;gt;&lt;br /&gt;
	        &amp;lt;?php&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Privileges ==&lt;br /&gt;
Not all users are given equal rights. For instance, a Super Administrator may be able to edit anyone&#039;s content, while a Publisher may only be able to edit their own. The authorise() member function can be used to determine if the current user has permission to do a certain task. The first parameter is used to identify which task we wish to check being allowed. The second represents the component we wish to retrieve the ACL information from.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
	$user = JFactory::getUser();&lt;br /&gt;
	&lt;br /&gt;
	if ($user-&amp;gt;authorise(&#039;core.edit&#039;, &#039;com_content&#039;))&lt;br /&gt;
	{&lt;br /&gt;
		echo &amp;quot;&amp;lt;p&amp;gt;You may edit all content.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		echo &amp;quot;&amp;lt;p&amp;gt;You may not edit all content.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	if ($user-&amp;gt;authorise(&#039;core.edit.own&#039;, &#039;com_content&#039;))&lt;br /&gt;
	{&lt;br /&gt;
		echo &amp;quot;&amp;lt;p&amp;gt;You may edit your own content.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		echo &amp;quot;&amp;lt;p&amp;gt;You may not edit your own content.&amp;lt;/p&amp;gt;&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Information about the current user is readily available in any part of your Joomla! extension. You need only fetch the object and access the member variables. You can authorise the user against the core permissions set, or create your own to suit your needs.&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
[https://api.joomla.org/cms-3/classes/Joomla.CMS.Factory.html#method_getUser Joomla 3.9 API reference] &lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Tutorials]][[Category:Framework]]&lt;br /&gt;
[[Category:Module Development]]&lt;br /&gt;
[[Category:Plugin Development]][[Category:Component Development]]&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=How_can_you_view_a_live_site_while_developing,_but_hide_it_from_others%3F&amp;diff=525579</id>
		<title>How can you view a live site while developing, but hide it from others?</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=How_can_you_view_a_live_site_while_developing,_but_hide_it_from_others%3F&amp;diff=525579"/>
		<updated>2018-09-20T10:54:00Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{version|2.5,3.x}}=== Introduction ===&lt;br /&gt;
&lt;br /&gt;
The method described below should be used for relatively minor modifications, such as adjusting menus or quickly reorganizing content sections. More complex tasks, such as installing new components or adjusting complex configuration settings should be performed and tested on a development server first. Not only does this keep your public site up and running, but it also lets you test at your leisure, thus reducing errors. One way to do it is to create a sub-domain (i. e., dev.yourdomain.com) and install Joomla! there just as it is installed on your public site.&lt;br /&gt;
&lt;br /&gt;
See also [[Taking the website temporarily offline]].&lt;br /&gt;
&lt;br /&gt;
=== Directions ===&lt;br /&gt;
&lt;br /&gt;
# Log in to the [[Back-end]], and choose: Site &amp;gt; Global Configuration.&lt;br /&gt;
# The first option you&#039;ll see is is to set the site offline. Choose &amp;quot;Yes&amp;quot; and press the Save button. This will prevent display of all site pages and replace them with the following message:&lt;br /&gt;
#: &amp;lt;pre&amp;gt;This site is down for maintenance. Please check back again soon.&amp;lt;/pre&amp;gt;&lt;br /&gt;
# While you are logged into the Back-end administrator system, you can still view the Front-end, by &lt;br /&gt;
#* {{JVer|3.x}}: clicking the site name in the top left corner&lt;br /&gt;
#* {{JVer|2.5}}: clicking the Preview link in the top right corner&lt;br /&gt;
#: This will display the site as it would appear to users along with a warning at the top that the site is down for maintenance.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;[[Category:FAQ]]&lt;br /&gt;
[[Category:Administration FAQ]]&lt;br /&gt;
[[Category:Getting Started FAQ]]&lt;br /&gt;
[[Category:Version 2.5 FAQ]]&lt;br /&gt;
[[Category:Version 3.0 FAQ]]&lt;br /&gt;
[[Category:Version 3.1 FAQ]]&lt;br /&gt;
[[Category:Component Development]]&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=How_can_you_view_a_live_site_while_developing,_but_hide_it_from_others%3F&amp;diff=525578</id>
		<title>How can you view a live site while developing, but hide it from others?</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=How_can_you_view_a_live_site_while_developing,_but_hide_it_from_others%3F&amp;diff=525578"/>
		<updated>2018-09-20T10:52:46Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{version|2.5,3.x}}=== Introduction ===&lt;br /&gt;
&lt;br /&gt;
The method described below should be used for relatively minor modifications, such as adjusting menus or quickly reorganizing content sections. More complex tasks, such as installing new components or adjusting complex configuration settings should be performed and tested on a development server first. Not only does this keep your public site up and running, but it also lets you test at your leisure, thus reducing errors. One way to do it is to create a sub-domain (i. e., dev.yourdomain.com) and install Joomla! there just as it is installed on your public site.&lt;br /&gt;
&lt;br /&gt;
See also [[Taking_the_website_temporarily_offline]].&lt;br /&gt;
&lt;br /&gt;
=== Directions ===&lt;br /&gt;
&lt;br /&gt;
# Log in to the [[Back-end]], and choose: Site &amp;gt; Global Configuration.&lt;br /&gt;
# The first option you&#039;ll see is is to set the site offline. Choose &amp;quot;Yes&amp;quot; and press the Save button. This will prevent display of all site pages and replace them with the following message:&lt;br /&gt;
#: &amp;lt;pre&amp;gt;This site is down for maintenance. Please check back again soon.&amp;lt;/pre&amp;gt;&lt;br /&gt;
# While you are logged into the Back-end administrator system, you can still view the Front-end, by &lt;br /&gt;
#* {{JVer|3.x}}: clicking the site name in the top left corner&lt;br /&gt;
#* {{JVer|2.5}}: clicking the Preview link in the top right corner&lt;br /&gt;
#: This will display the site as it would appear to users along with a warning at the top that the site is down for maintenance.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;[[Category:FAQ]]&lt;br /&gt;
[[Category:Administration FAQ]]&lt;br /&gt;
[[Category:Getting Started FAQ]]&lt;br /&gt;
[[Category:Version 2.5 FAQ]]&lt;br /&gt;
[[Category:Version 3.0 FAQ]]&lt;br /&gt;
[[Category:Version 3.1 FAQ]]&lt;br /&gt;
[[Category:Component Development]]&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=File_form_field_type&amp;diff=482660</id>
		<title>File form field type</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=File_form_field_type&amp;diff=482660"/>
		<updated>2018-04-30T11:29:31Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: adding link to file-system docs&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;&amp;lt;languages /&amp;gt;&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
Provides an input field for files&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;type&#039;&#039;&#039; (mandatory) must be &#039;&#039;file&#039;&#039;.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;name&#039;&#039;&#039; (mandatory) is the unique name of the field.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;label&#039;&#039;&#039; (mandatory) (translatable) is the descriptive title of the field.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;description&#039;&#039;&#039; (optional) (translatable) is text that will be shown as a tooltip when the user moves the mouse over the drop-down box.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;default&#039;&#039;&#039; (optional) (not translatable) is the default value, but doesn&#039;t mean much for a file.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;size&#039;&#039;&#039; (optional) is the width of the file box in characters.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
* [http://www.w3schools.com/tags/att_input_accept.asp &#039;&#039;&#039;accept&#039;&#039;&#039;] (optional) Tells the browser what MIME types your form will allow to be uploaded.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;class&#039;&#039;&#039; (optional) is a CSS class name for the HTML form field.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;labelclass&#039;&#039;&#039; (optional) adds a CSS class for form field&#039;s label; for Joomla 2.5.4+&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;disabled&#039;&#039;&#039; (optional)  HTML equivalent attribute&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;onchange&#039;&#039;&#039; (optional)  HTML equivalent attribute (javascript use)&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;required&#039;&#039;&#039; Cannot be used with this field type.  If the field is marked as required it will &#039;&#039;&#039;always&#039;&#039;&#039; fail validation regardless of whether a file has been uploaded or not.  The suggested workaround is to add a &#039;&#039;&#039;filerequired&#039;&#039;&#039; attribute which can be tested in your own file handling code.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;validate&#039;&#039;&#039; (optional)  Whether to Joomla validate the field according to rules&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;showon&#039;&#039;&#039; (optional)  Allows you to hide the field based on the value(s) of another field; for Joomla 3.2.4+&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;&lt;br /&gt;
When using the file input type you should always add the attribute enctype=&amp;quot;multipart/form-data&amp;quot; to your form tag. Otherwise, the uploaded files will not be attached correctly.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note 2:&#039;&#039;&#039;&lt;br /&gt;
You can put a soft limit file size by adding a hidden field with name=&amp;quot;MAX_FILE_SIZE&amp;quot; and value the maximum allowed bytes which is handled by php, but you must also handle it in your code with or without it.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
Example XML field definition:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;field name=&amp;quot;myfilevalue&amp;quot; type=&amp;quot;file&amp;quot; label=&amp;quot;Enter some text&amp;quot; description=&amp;quot;Choose an image from your computer with maximum 100KB&amp;quot; size=&amp;quot;10&amp;quot; accept=&amp;quot;image/*&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;=== See also === &amp;lt;!--T:18--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:19--&amp;gt;&lt;br /&gt;
* [[S:MyLanguage/Standard form field types|List of standard form field types]]&lt;br /&gt;
* [[S:MyLanguage/How_to_use_the_filesystem_package|How to use the filesystem package]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
[[Category:Standard form field types]]&lt;br /&gt;
[[Category:Form fields]]&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Talk:Radio_form_field_type&amp;diff=405009</id>
		<title>Talk:Radio form field type</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Talk:Radio_form_field_type&amp;diff=405009"/>
		<updated>2017-05-16T12:54:05Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: Created page with &amp;quot;Not sure if the values have to be numeric, they are in the three examples, be good to explain here.&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Not sure if the values have to be numeric, they are in the three examples, be good to explain here.&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=J3.x:Adding_JavaScript_and_CSS_to_the_page&amp;diff=375593</id>
		<title>J3.x:Adding JavaScript and CSS to the page</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=J3.x:Adding_JavaScript_and_CSS_to_the_page&amp;diff=375593"/>
		<updated>2017-03-23T10:43:22Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: removing deprecated jhtml notes, as this was removed in joomla 3 in 2012, so is now not relevant&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;&amp;lt;languages /&amp;gt;&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Inserting from a File == &amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
To have a well-formed HTML document, you must put all references to Javascript and CSS files within the &amp;lt;code&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/code&amp;gt; portion. Since Joomla! generates all the HTML that makes up a page before output, it is possible to add these references within the &amp;lt;head&amp;gt; tags from your extension. The simplest way to do this is to make use of the functionality built in to Joomla.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
===JDocument=== &amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
First, get a reference to the current document object:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$document = JFactory::getDocument();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
Then for a stylesheet, use this code:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$document-&amp;gt;addStyleSheet($url);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
To add a Javascript file, use this code:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$document-&amp;gt;addScript($url);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
where &amp;lt;code&amp;gt;$url&amp;lt;/code&amp;gt; is the variable containing the full path to the javascript or CSS file for example:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;JUri::base() . &#039;templates/custom/js/sample.js&#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
Note this will **NOT** include Mootools or jQuery. If your script requires Mootools or jQuery see [[S:MyLanguage/Javascript_Frameworks|Javascript Frameworks]] for full details on how to include them (note jQuery can only be included natively on Joomla! 3.0+).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
It used to be possible to do this with JHTML, however, this was deprecated in Joomla 2.5 and removed in Joomla 3.x.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Adding the options to your JavaScript code == &amp;lt;!--T:42--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
{{Joomla version|version=3.7|time=and after|comment=&amp;lt;translate&amp;gt;&amp;lt;!--T:50--&amp;gt;&lt;br /&gt;
Only available in Joomla! 3.7 and higher&amp;lt;/translate&amp;gt;|align=left}}&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:43--&amp;gt;&lt;br /&gt;
Beside adding inline scripts, Joomla! provide mechanism to store the options in the &amp;quot;optionsStorage&amp;quot;.&lt;br /&gt;
This is allowed to nicely manage an existing options on the server side and on the client side. And allow to place all JavaScript logic to the JavaScript file, that will be cached by browser.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:44--&amp;gt;&lt;br /&gt;
Joomla! use special mechanism for &amp;quot;lazy loading&amp;quot; the options on the client side. It do not use inline JavaScript, that is good for page rendering speed, and make your site more friendly for the Speed Tester (eg Google).&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:45--&amp;gt;&lt;br /&gt;
Thus use &amp;quot;optionsStorage&amp;quot; preferred, than use inline JavaScript to add the script options.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:46--&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Example of use&#039;&#039;&#039;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:47--&amp;gt;&lt;br /&gt;
Add the script options to your module:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$document = JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptOptions(&#039;mod_example&#039;,&lt;br /&gt;
    &#039;colors&#039; =&amp;gt; array(&#039;selector&#039; =&amp;gt; &#039;body&#039;, &#039;color&#039; =&amp;gt; &#039;orange&#039;),&lt;br /&gt;
    &#039;sliderOptions&#039; =&amp;gt; array(&#039;selector&#039; =&amp;gt; &#039;.my-slider&#039;, &#039;timeout&#039; =&amp;gt; 300, &#039;fx&#039; =&amp;gt; &#039;fade&#039;),&lt;br /&gt;
));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:48--&amp;gt;&lt;br /&gt;
Access to your options on the client side:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var myOptions = Joomla.getOptions(&#039;mod_example&#039;);&lt;br /&gt;
console.log(myOptions.colors); // Print in the browser console your options&lt;br /&gt;
console.log(myOptions.sliderOptions);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:49--&amp;gt;&lt;br /&gt;
Override the options on server side (possible until the head rendering):&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$document  = JFactory::getDocument();&lt;br /&gt;
// Get existing options&lt;br /&gt;
$myOptions = $document-&amp;gt;getScriptOptions(&#039;mod_example&#039;);&lt;br /&gt;
// Change the value&lt;br /&gt;
$myOptions[&#039;colors&#039;] = array(&#039;selector&#039; =&amp;gt; &#039;body&#039;, &#039;color&#039; =&amp;gt; &#039;green&#039;);&lt;br /&gt;
// Set new options&lt;br /&gt;
$document-&amp;gt;addScriptOptions(&#039;mod_example&#039;, $myOptions);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Inserting inline scripts from within a PHP file == &amp;lt;!--T:32--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:33--&amp;gt;&lt;br /&gt;
If your Javascript or CSS are generated using PHP, you can add the script or stylesheet directly into the head of your document:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$document = JFactory::getDocument();&lt;br /&gt;
&lt;br /&gt;
// Add Javascript&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration(&#039;&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline JavaScript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
&#039;);&lt;br /&gt;
&lt;br /&gt;
// Add styles&lt;br /&gt;
$style = &#039;body {&#039;&lt;br /&gt;
        . &#039;background: #00ff00;&#039;&lt;br /&gt;
        . &#039;color: rgb(0,0,255);&#039;&lt;br /&gt;
        . &#039;}&#039;; &lt;br /&gt;
$document-&amp;gt;addStyleDeclaration($style);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Javascript Example === &amp;lt;!--T:34--&amp;gt;&lt;br /&gt;
For example, the following code is used to define a custom tool tip that takes advantage of mootools.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
function getToolTipJS($toolTipVarName, $toolTipClassName){&lt;br /&gt;
    $javascript = &#039;window.addEvent(\&amp;quot;domready\&amp;quot;, function(){&#039; .&amp;quot;\n&amp;quot;;&lt;br /&gt;
    $javascript .= &amp;quot;\t&amp;quot;  .&#039;var $toolTipVarName = new Tips($$(&amp;quot;&#039; . $toolTipVarName .&#039;&amp;quot;), {&#039; .&amp;quot;\n&amp;quot;;&lt;br /&gt;
    $javascript .= &amp;quot;\t\t&amp;quot;   .&#039;className: &amp;quot;&#039; .$toolTipClassName .&#039;&amp;quot;,&#039; .&amp;quot;\n&amp;quot;;&lt;br /&gt;
    $javascript .= &amp;quot;\t\t&amp;quot;   .&#039;initialize: function(){&#039; .&amp;quot;\n&amp;quot;;&lt;br /&gt;
    $javascript .= &amp;quot;\t\t\t&amp;quot;    .&#039;this.fx = new Fx.Style(this.toolTip, &amp;quot;opacity&amp;quot;, {duration: 500, wait: false}).set(0);&#039; .&amp;quot;\n&amp;quot;;&lt;br /&gt;
    $javascript .= &amp;quot;\t\t&amp;quot;   .&#039;},&#039; .&amp;quot;\n&amp;quot;;&lt;br /&gt;
    $javascript .= &amp;quot;\t\t&amp;quot;   .&#039;onShow: function(toolTip){&#039; .&amp;quot;\n&amp;quot;;&lt;br /&gt;
    $javascript .= &amp;quot;\t\t\t&amp;quot;    .&#039;this.fx.start(1);&#039; .&amp;quot;\n&amp;quot;;&lt;br /&gt;
    $javascript .= &amp;quot;\t\t&amp;quot;   .&#039;},&#039; .&amp;quot;\n&amp;quot;;&lt;br /&gt;
    $javascript .= &amp;quot;\t\t&amp;quot;   .&#039;onHide: function(toolTip) {&#039; .&amp;quot;\n&amp;quot;;&lt;br /&gt;
    $javascript .= &amp;quot;\t\t\t&amp;quot;    .&#039;this.fx.start(0);&#039; .&amp;quot;\n&amp;quot;;&lt;br /&gt;
    $javascript .= &amp;quot;\t\t&amp;quot;   .&#039;}&#039; .&amp;quot;\n&amp;quot;;&lt;br /&gt;
    $javascript .= &amp;quot;\t&amp;quot;  .&#039;});&#039; .&amp;quot;\n&amp;quot;;&lt;br /&gt;
    $javascript .= &#039;});&#039; .&amp;quot;\n\n&amp;quot;;&lt;br /&gt;
    return $javascript;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$document = JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addStyleSheet(&amp;quot;/joomla/components/com_mycustomcomponent/css/mytooltip.css&amp;quot;,&#039;text/css&#039;,&amp;quot;screen&amp;quot;);&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration(getToolTipJS(&amp;quot;mytool&amp;quot;,&amp;quot;MyToolTip&amp;quot;));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:35--&amp;gt;&lt;br /&gt;
Note that in order for this Javascript to be functionally useful, it would be necessary to include the appropriate class name in the HTML, as well as providing the &amp;lt;code&amp;gt;mytooltip.css&amp;lt;/code&amp;gt; file. Both are outside the scope of this article.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== CSS Examples === &amp;lt;!--T:36--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:37--&amp;gt;&lt;br /&gt;
This is also useful if your inserting a form field of CSS into your code. For example in a module, you might want a user to choose to call the colour of the border. After calling the form fields value and assigning it a variable $bordercolor in mod_example.php. Then in tmpl/default.php you can include the following:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$document = JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addStyleSheet(&#039;mod_example/mod_example.css&#039;, array(), true);&lt;br /&gt;
$style = &#039;#example {&lt;br /&gt;
	border-color:#&#039; . $bordercolor . &#039;;&lt;br /&gt;
	}&#039;;&lt;br /&gt;
$document-&amp;gt;addStyleDeclaration( $style );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:38--&amp;gt;&lt;br /&gt;
Here mod_example.css contains the CSS file of any non-parameter based styles. Then the bordercolor parameter/form field is added in separately.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==Add Custom Tag== &amp;lt;!--T:39--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:40--&amp;gt;&lt;br /&gt;
There will be some occasions where even these functions are not flexible enough, as they are limited to writing the contents of &amp;lt;code&amp;gt;&amp;lt;script /&amp;gt;&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;&amp;lt;style /&amp;gt;&amp;lt;/code&amp;gt; tags, and cannot add anything outside those tags. One example would be the inclusion of a stylesheet link within conditional comments, so that it is picked up only by Internet Explorer 6 and earlier. To do this, use &amp;lt;code&amp;gt;$document-&amp;gt;addCustomTag&amp;lt;/code&amp;gt;:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$stylelink = &#039;&amp;lt;!--[if lte IE 6]&amp;gt;&#039; .&amp;quot;\n&amp;quot;;&lt;br /&gt;
$stylelink .= &#039;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;../css/IEonly.css&amp;quot; /&amp;gt;&#039; .&amp;quot;\n&amp;quot;;&lt;br /&gt;
$stylelink .= &#039;&amp;lt;![endif]--&amp;gt;&#039; .&amp;quot;\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
$document = JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addCustomTag($stylelink);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:41--&amp;gt;&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Tutorials]]&lt;br /&gt;
[[Category:Component Development]]&lt;br /&gt;
[[Category:Module Development]]&lt;br /&gt;
[[Category:JavaScript]]&lt;br /&gt;
[[Category:CSS]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Textarea_form_field_type&amp;diff=365315</id>
		<title>Textarea form field type</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Textarea_form_field_type&amp;diff=365315"/>
		<updated>2017-02-17T10:05:22Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: adding hint / placeholder&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;&amp;lt;languages /&amp;gt;&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
The &#039;&#039;&#039;textarea&#039;&#039;&#039; form field type provides a text area for entry of multi-line text. If the field has a value saved, this value is displayed when the page is first loaded. If not, the default value (if any) is selected.&amp;lt;/translate&amp;gt;&lt;br /&gt;
[[Image:Params.textarea.jpg|right]]&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;type&#039;&#039;&#039; (mandatory) must be &#039;&#039;textarea&#039;&#039;.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;name&#039;&#039;&#039; (mandatory) is the unique name of the field.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;label&#039;&#039;&#039; (mandatory) (translatable) is the descriptive title of the field.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;rows&#039;&#039;&#039; (mandatory) is the height of the visible text area in lines. If omitted the height is determined by the browser. The value of rows does not limit the number of lines that may be entered.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;cols&#039;&#039;&#039; (mandatory) is the width of the visible text area in characters. If omitted the width is determined by the browser. The value of cols does not limit the number of characters that may be entered.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;default&#039;&#039;&#039; (optional) (not translatable) is the default value.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;description&#039;&#039;&#039; (optional) (translatable) is text that will be shown as a tooltip when the user moves the mouse over the drop-down box.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;class&#039;&#039;&#039; (optional)  is a CSS class name for the HTML form field. If omitted this will default to &#039;text_area&#039;.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;filter&#039;&#039;&#039; (optional) allow the system to save certain html tags or raw data.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:19--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;hint&#039;&#039;&#039; (optional) The text displayed in the html placeholder element, usually a lighter coloured hint displayed inside an blank field.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
Example XML field definition:&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;field name=&amp;quot;mytextarea&amp;quot; type=&amp;quot;textarea&amp;quot; default=&amp;quot;default&amp;quot; label=&amp;quot;Enter some text&amp;quot; description=&amp;quot;&amp;quot; rows=&amp;quot;10&amp;quot; cols=&amp;quot;5&amp;quot; /&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
Use the raw filter to ensure that html code is preserved when the form is processed:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;field name=&amp;quot;mytextarea&amp;quot; type=&amp;quot;textarea&amp;quot; default=&amp;quot;default&amp;quot; label=&amp;quot;Enter some html&amp;quot; description=&amp;quot;&amp;quot; rows=&amp;quot;10&amp;quot; cols=&amp;quot;5&amp;quot; filter=&amp;quot;raw&amp;quot;/&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;=== Tips === &amp;lt;!--T:13--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
* If you need to line break just encode &amp;lt;code&amp;gt;&amp;amp;lt;br /&amp;amp;gt;&amp;lt;/code&amp;gt; in the XML config file like this:&amp;lt;/translate&amp;gt; &amp;lt;code&amp;gt;&amp;amp;amp;lt;br /&amp;amp;amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
* If you need a new line character in your default value, add &amp;lt;code&amp;gt;&amp;amp;amp;#13;&amp;amp;amp;#10;&amp;lt;/code&amp;gt; to the default parameter.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;=== See also === &amp;lt;!--T:16--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
* [[S:MyLanguage/Text form field type|Text form field type]]&lt;br /&gt;
* [[S:MyLanguage/Standard form field types|List of standard form field types]]&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
[[Category:Standard form field types]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Text_form_field_type&amp;diff=365314</id>
		<title>Text form field type</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Text_form_field_type&amp;diff=365314"/>
		<updated>2017-02-17T10:04:40Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: adding hint / placeholder&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;&amp;lt;languages /&amp;gt;&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
The &#039;&#039;&#039;text&#039;&#039;&#039; form field type provides a text box for data entry. If the field has a value saved, this value is displayed when the page is first loaded. If not, the default value (if any) is selected.&amp;lt;/translate&amp;gt; &lt;br /&gt;
[[Image:Params.text.jpg|right]]&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;type&#039;&#039;&#039; (mandatory) must be &#039;&#039;text&#039;&#039;.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;name&#039;&#039;&#039; (mandatory) is the unique name of the field.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;label&#039;&#039;&#039; (mandatory) (translatable) is the descriptive title of the field.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;size&#039;&#039;&#039; (optional) is the width of the text box in characters. If omitted the width is determined by the browser. The value of size does not limit the number of characters that may be entered.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;maxlength&#039;&#039;&#039; (optional) limits the number of characters that may be entered.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;default&#039;&#039;&#039; (optional) (not translatable) is the default value.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;description&#039;&#039;&#039; (optional) (translatable) is text that will be shown as a tooltip when the user moves the mouse over the drop-down box.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;class&#039;&#039;&#039; (optional) is a CSS class name for the HTML form field. If omitted this will default to &#039;text_area&#039;.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;readonly&#039;&#039;&#039; (optional) The field cannot be changed and will automatically inherit the default value&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;disabled&#039;&#039;&#039; (optional) The field cannot be changed and will automatically inherit the default value - it will also not submit&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;required&#039;&#039;&#039; (optional) The field must be filled before submitting the form.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;filter&#039;&#039;&#039; (optional) allow the system to save certain html tags or raw data.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;message&#039;&#039;&#039; (optional) The error message that will be displayed instead of the default message.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;hint&#039;&#039;&#039; (optional) The text displayed in the html placeholder element, usually a lighter coloured hint displayed inside an blank field.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
Example XML field definition:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;field name=&amp;quot;mytextvalue&amp;quot; type=&amp;quot;text&amp;quot; default=&amp;quot;Some text&amp;quot; label=&amp;quot;Enter some text&amp;quot; description=&amp;quot;&amp;quot; size=&amp;quot;10&amp;quot; /&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
Use the integer filter to ensure that letters types get stripped when the form is processed.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;field name=&amp;quot;myintvalue&amp;quot; type=&amp;quot;text&amp;quot; default=&amp;quot;8&amp;quot; label=&amp;quot;Enter some text&amp;quot; description=&amp;quot;Enter some description&amp;quot; filter=&amp;quot;integer&amp;quot; /&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
Use the raw filter to ensure that html code is preserved when the form is processed.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;field name=&amp;quot;myhtmlvalue&amp;quot; type=&amp;quot;text&amp;quot; default=&amp;quot;&amp;quot; label=&amp;quot;Enter some text&amp;quot; description=&amp;quot;Enter some description&amp;quot; filter=&amp;quot;raw&amp;quot; /&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;=== See also === &amp;lt;!--T:18--&amp;gt;&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:19--&amp;gt;&lt;br /&gt;
* [[S:MyLanguage/Textarea form field type|Textarea form field type]]&lt;br /&gt;
* [[S:MyLanguage/Standard form field types|List of standard form field types]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
[[Category:Standard form field types]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Portal:Learn_More&amp;diff=365245</id>
		<title>Portal:Learn More</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Portal:Learn_More&amp;diff=365245"/>
		<updated>2017-02-17T01:10:22Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: adding a link, seemed a useful example&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;languages/&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
Joomla! is an [[S:MyLanguage/Joomla! Awards|award-winning content management system (CMS)]], which enables you to build Web sites and powerful online applications. Many aspects, including its ease-of-use and extensibility, have made Joomla! the most popular Web site software available. Best of all, Joomla! is an open source solution that is freely available to everyone, this also means that you can modify the source code according to your needs and gain maximum advantage. &lt;br /&gt;
&lt;br /&gt;
==What&#039;s a content management system (CMS)?== &amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
A content management system is software that keeps track of every piece of content on your Web site, much like your local public library keeps track of books and stores them. Content can be simple text, photos, music, video, documents, or just about anything you can think of. A major advantage of using a CMS is that it requires almost no technical skill or knowledge to manage. The CMS manages all your content, so you don&#039;t have to. CMS also helps you track your content easily and help you develop and manage your content in the best possible way.&lt;br /&gt;
&lt;br /&gt;
==What are some real world examples of what Joomla! can do?== &amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
Joomla is used all over the world to power Web sites of all shapes and sizes. For example:&lt;br /&gt;
&lt;br /&gt;
*Corporate Web sites or portals&lt;br /&gt;
*Corporate intranets and extranets&lt;br /&gt;
*Online magazines, newspapers, and publications&lt;br /&gt;
*E-commerce and online reservations&lt;br /&gt;
*Government applications&lt;br /&gt;
*Small business Web sites&lt;br /&gt;
*Non-profit and organizational Web sites&lt;br /&gt;
*Community-based portals&lt;br /&gt;
*School and church Web sites&lt;br /&gt;
*Personal or family homepages&lt;br /&gt;
 &lt;br /&gt;
==Who uses Joomla?== &amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
Here are just a few examples of Web sites that use Joomla:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
*Salon sukni ślubnych (Bridal Fashion - Polish) - http://www.mlodaimoda.pl/&lt;br /&gt;
*Alliance for Catholic Education - https://ace.nd.edu/&lt;br /&gt;
*Alain Milliat (Juices and Marmelades - France) - http://www.alain-milliat.com/&lt;br /&gt;
*Citibank (Financial institution intranet) - Not publicly accessible&lt;br /&gt;
*La Folie Douce - http://www.lafoliedouce.com/&lt;br /&gt;
*United Nations Regional Information Centre (UNRIC) - http://www.unric.org/&lt;br /&gt;
*FUNX (Radiostation - Netherlands) - http://www.funx.nl/&lt;br /&gt;
*PlayShakespeare.com (Cultural) - http://www.playshakespeare.com&lt;br /&gt;
*Cheap Wine Band (Music - German) - http://www.cheapwineband.de/&lt;br /&gt;
*Royal Dornoch Golf Club, est 1621 (Sport - Golf) - http://royaldornoch.com/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
More examples of companies using Joomla! can be found in the [http://community.joomla.org/showcase/ Joomla! Community Site Showcase].&lt;br /&gt;
For Government sites using Joomla, view http://joomlagov.info.&lt;br /&gt;
&lt;br /&gt;
==I need to build a site for a client. How will Joomla! help me?== &amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;[[File:Help30-Content-Article-Manager-screen.png|400px|right|link=]]&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
Joomla! is designed to be easy to install and set up even if you&#039;re not an advanced user. Many Web hosting services offer a single-click install or auto installers, getting your new site up and running in just a few minutes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
Since Joomla is so easy to use, as a [[S:MyLanguage/Web designers|Web designer]] or [[S:MyLanguage/Portal:Developers|Developer]], you can quickly build sites for your clients. Then, with a minimal amount of instruction, you can empower your clients to easily manage their own sites themselves.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
If your clients need specialized functionality, Joomla! is highly extensible and thousands of extensions (most for free under the GPL license) are available in the [http://extensions.joomla.org/ Joomla! Extensions Directory].&lt;br /&gt;
&amp;lt;/translate&amp;gt;{{-}}&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==How can I be sure there will be Joomla! support in the future?== &amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;[[File:Winner - Best CMS.png|right|80px|link=]]&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
Joomla! is the most popular open source CMS currently available as evidenced by a vibrant and growing community of friendly users and talented developers. Joomla&#039;s roots go back to 2000 and, with over 200,000 community users and contributors, the future looks bright for the award-winning Joomla! Project.&lt;br /&gt;
&amp;lt;/translate&amp;gt;{{-}}&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==I&#039;m a developer. What are some advanced ways I can use Joomla?== &amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;[[File:MVC Diagram.png|right|350px|link=]]&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
Many companies and organizations have requirements that go beyond what is available in the basic Joomla! package. In those cases, Joomla&#039;s powerful application framework makes it easy for developers to create sophisticated add-ons that extend the power of Joomla! into virtually unlimited directions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
The core Joomla framework enables developers to quickly and easily build:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:19--&amp;gt;&lt;br /&gt;
*Inventory control systems&lt;br /&gt;
*Data reporting tools&lt;br /&gt;
*Application bridges&lt;br /&gt;
*Custom product catalogs&lt;br /&gt;
*Integrated e-commerce systems&lt;br /&gt;
*Complex business directories&lt;br /&gt;
*Reservation systems&lt;br /&gt;
*Communication tools&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
Since Joomla! is based on PHP and MySQL, you&#039;re building powerful applications on an open platform anyone can use, share, and support. To find out more information on leveraging the Joomla! framework, visit the [http://developer.joomla.org/ Joomla! Developer Network].&lt;br /&gt;
&lt;br /&gt;
==Joomla! seems the right solution for me. How do I get started?== &amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
Joomla! is free, open, and available to anyone under the [http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GPL license]. Read [http://www.joomla.org/about-joomla/getting-started.html Getting Started with Joomla!] to find out the basics then [http://demo.joomla.org/ try out our online demo] and you&#039;ll quickly discover how simple Joomla! is. If you&#039;re ready to install Joomla, download the latest version [http://www.joomla.org/download.html here]. You&#039;ll be up and running in no time by following the [[S:MyLanguage/J3.x:Installing_Joomla|Installing Joomla!]] instructions.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;large-6 column&amp;quot; style=&amp;quot;text-align:center&amp;quot;&amp;gt;[[File:Test Drive Joomla.png|link=http://demo.joomla.org/]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;large-6 column&amp;quot; style=&amp;quot;text-align:center&amp;quot;&amp;gt;[[File:Download Joomla.png|link=http://www.joomla.org/download.html]]&amp;lt;/div&amp;gt;&lt;br /&gt;
{{-}}&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Credits and Thanks == &amp;lt;!--T:24--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
Producing world class Open Source software takes a lot of active support from community members and partnering businesses. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:26--&amp;gt;&lt;br /&gt;
* [http://developer.joomla.org/tracker/volunteer-activity.html Volunteer Activity] for Joomla! project.&lt;br /&gt;
* [[S:MyLanguage/Joomla! Credits and Thanks|Partnering Businesses]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:23--&amp;gt;&lt;br /&gt;
[[Category:Landing Pages]]&lt;br /&gt;
[[Category:Learn More Pages|Learn More Pages]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Custom_error_pages&amp;diff=328467</id>
		<title>Custom error pages</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Custom_error_pages&amp;diff=328467"/>
		<updated>2016-08-22T10:06:07Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: adding info on including modules in error pages&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;&amp;lt;languages /&amp;gt;&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&amp;lt;noinclude&amp;gt;{{JSplit}}&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
Joomla! uses the &amp;lt;tt&amp;gt;templates/system/error.php&amp;lt;/tt&amp;gt; file to handle several HTTP Status errors, including &amp;quot;403 Forbidden&amp;quot;, &amp;quot;404 Not Found&amp;quot;, and &amp;quot;500 Internal Server&amp;quot; errors. You can style the error results, if desired.&lt;br /&gt;
&amp;lt;/translate&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
It is important to understand that &#039;&#039;error.php&#039;&#039; is an independent file from the Joomla! CMS but dependent on the Joomla! Platform. Plugins do not run on the file. You cannot include modules or use  &amp;lt;tt&amp;gt;&amp;lt;jdoc:include&amp;gt;&amp;lt;/tt&amp;gt; statements.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
====Overriding the System Error Results==== &amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
To override the system error results, copy the &amp;lt;tt&amp;gt;templates/system/error.php&amp;lt;/tt&amp;gt; file into your &amp;lt;tt&amp;gt;templates/&amp;lt;template-name&amp;gt;&amp;lt;/tt&amp;gt; directory.&lt;br /&gt;
&amp;lt;/translate&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
If it finds one, Joomla! will use the &amp;lt;tt&amp;gt;error.php&amp;lt;/tt&amp;gt; file from the current template, in place of the system file.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
You can format the page, as desired, to match your template.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
====Overriding the System Styling==== &amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
If you want to change the styling, copy the &amp;lt;tt&amp;gt;templates/system/css/error.css&amp;lt;/tt&amp;gt; file into your &amp;lt;tt&amp;gt;templates/&amp;lt;template-name&amp;gt;/css&amp;lt;/tt&amp;gt; directory.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
Next, update your &amp;lt;tt&amp;gt;templates/&amp;lt;template-name&amp;gt;/error.php&amp;lt;/tt&amp;gt; file to reference the new location of the stylesheet by changing this line, accordingly:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;&amp;lt;?php echo $this-&amp;gt;baseurl; ?&amp;gt;/templates/system/css/error.css&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
Then, simply change the &amp;lt;tt&amp;gt;error.css&amp;lt;/tt&amp;gt;, as desired, for your styling requirements.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
====Customizing Error Messages==== &amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
You can add conditional logic to vary the message returned, dependent upon the specific error code.&lt;br /&gt;
&amp;lt;/translate&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
Here is an example of how to trap a 404 error and provide a custom message.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php  if ($this-&amp;gt;error-&amp;gt;getCode() == &#039;404&#039;) { ?&amp;gt;&lt;br /&gt;
	&amp;lt;div id=&amp;quot;errorboxheader&amp;quot;&amp;gt;Page not found&amp;lt;/div&amp;gt;&lt;br /&gt;
		&amp;lt;div id=&amp;quot;errorboxbody&amp;quot;&amp;gt;&amp;lt;p&amp;gt;Sorry! That page cannot be found.&amp;lt;/p&amp;gt;&lt;br /&gt;
		&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;?php } ?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
====HTTP Status Code==== &amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
When a request is made for a page on your site, the server returns an HTTP status code in response to the request. Joomla! returns a &#039;200 - the server successfully returned the page&#039; for error pages. This is problematic for those working with Google Webmaster Services and trying to get a sitemap resolved.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
If you want Joomla! to return a status code for the error, you can do so by adding logic before the DOCTYPE line, as follows:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php &lt;br /&gt;
if ($this-&amp;gt;error-&amp;gt;getCode() == &#039;404&#039;) {&lt;br /&gt;
	header(&amp;quot;HTTP/1.0 404 Not Found&amp;quot;);&lt;br /&gt;
} ?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
====More HTTP Status Code Information==== &amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
* [[S:MyLanguage/Create_a_Custom_404_Error_Page|Create a Custom 404 Error Page]]&lt;br /&gt;
* [http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html HTTP/1.1 Status Code Definitions]&lt;br /&gt;
* [[wikipedia:List_of_HTTP_status_codes|List of HTTP status codes]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
====Using Theme Header and Footer on Standard Error Page==== &amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
{{JVer|1.5}}&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
If you want to see the error page in theme design and don&#039;t like redirecting to error page URL or duplicating HTML in the error page template, here is a way to apply your theme template to the error page.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
First, put the following code in &amp;lt;tt&amp;gt;templates/&amp;lt;template-name&amp;gt;/error.php&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// no direct access&lt;br /&gt;
defined( &#039;_JEXEC&#039; ) or die( &#039;Restricted access&#039; );&lt;br /&gt;
&lt;br /&gt;
include dirname(__FILE__) . &amp;quot;/index.php&amp;quot;;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
Then make the following edits to &amp;lt;tt&amp;gt;templates/&amp;lt;template-name&amp;gt;/index.php&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:19--&amp;gt;&lt;br /&gt;
1. Find the following code in &amp;lt;tt&amp;gt;index.php&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
and replace it with the following&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php if (!$this-&amp;gt;error-&amp;gt;getCode()) : ?&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;?php else : ?&amp;gt; &lt;br /&gt;
&amp;lt;title&amp;gt;&amp;lt;?php echo $this-&amp;gt;error-&amp;gt;getCode() ?&amp;gt; - &amp;lt;?php echo $this-&amp;gt;title; ?&amp;gt;&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;lt;?php endif; ?&amp;gt;  &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
2. Find the following code in &amp;lt;tt&amp;gt;index.php&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;component&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
and replace it with the following&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php if ($this-&amp;gt;error-&amp;gt;getCode()) : /* check if we are on error page, if yes - display error message */ ?&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;?php echo $this-&amp;gt;error-&amp;gt;getCode() ?&amp;gt; - &amp;lt;?php echo $this-&amp;gt;error-&amp;gt;message ?&amp;gt;&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;?php echo JText::_(&#039;JERROR_LAYOUT_NOT_ABLE_TO_VISIT&#039;); ?&amp;gt;&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;ol&amp;gt;&lt;br /&gt;
    &amp;lt;li&amp;gt;&amp;lt;?php echo JText::_(&#039;JERROR_LAYOUT_AN_OUT_OF_DATE_BOOKMARK_FAVOURITE&#039;); ?&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;li&amp;gt;&amp;lt;?php echo JText::_(&#039;JERROR_LAYOUT_SEARCH_ENGINE_OUT_OF_DATE_LISTING&#039;); ?&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;li&amp;gt;&amp;lt;?php echo JText::_(&#039;JERROR_LAYOUT_MIS_TYPED_ADDRESS&#039;); ?&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;li&amp;gt;&amp;lt;?php echo JText::_(&#039;JERROR_LAYOUT_YOU_HAVE_NO_ACCESS_TO_THIS_PAGE&#039;); ?&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;li&amp;gt;&amp;lt;?php echo JText::_(&#039;JERROR_LAYOUT_REQUESTED_RESOURCE_WAS_NOT_FOUND&#039;); ?&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;li&amp;gt;&amp;lt;?php echo JText::_(&#039;JERROR_LAYOUT_ERROR_HAS_OCCURRED_WHILE_PROCESSING_YOUR_REQUEST&#039;); ?&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;/ol&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;?php echo JText::_(&#039;JERROR_LAYOUT_PLEASE_TRY_ONE_OF_THE_FOLLOWING_PAGES&#039;); ?&amp;gt;&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;ul&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;&amp;lt;?php echo $this-&amp;gt;baseurl; ?&amp;gt;/index.php&amp;quot; title=&amp;quot;&amp;lt;?php echo JText::_(&#039;JERROR_LAYOUT_GO_TO_THE_HOME_PAGE&#039;); ?&amp;gt;&amp;quot;&amp;gt;&amp;lt;?php echo JText::_(&#039;JERROR_LAYOUT_HOME_PAGE&#039;); ?&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;p&amp;gt;&amp;lt;?php echo JText::_(&#039;JERROR_LAYOUT_PLEASE_CONTACT_THE_SYSTEM_ADMINISTRATOR&#039;); ?&amp;gt;.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;?php else : ?&amp;gt;&lt;br /&gt;
  &amp;lt;jdoc:include type=&amp;quot;component&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;?php endif; ?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:23--&amp;gt;&lt;br /&gt;
Now your theme template is applied to error pages too.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:24--&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Module includes in template will not work on error page created by this method (but will work on other pages).&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
====Using modules in error pages==== &amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
Modules cannot be included in error pages in the same way as the template&#039;s index.php because you cannot use  &amp;lt;tt&amp;gt;&amp;lt;jdoc:include&amp;gt;&amp;lt;/tt&amp;gt; statements.  There is an alternative way using &amp;lt;tt&amp;gt;JModuleHelper&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&amp;lt;/translate&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:26--&amp;gt;&lt;br /&gt;
To include a single module by title, you can use:&lt;br /&gt;
&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
if (JModuleHelper::getModule(&#039;menu&#039;)) { &lt;br /&gt;
    echo $doc-&amp;gt;getBuffer(&#039;module&#039;, &#039;menu&#039;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:27--&amp;gt;&lt;br /&gt;
To include a multiple modules by position, you can use:&lt;br /&gt;
&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$modules = JModuleHelper::getModules( &#039;footer_3&#039; );&lt;br /&gt;
$attribs[&#039;style&#039;] = &#039;xhtml&#039;;&lt;br /&gt;
foreach ($modules AS $module ) {&lt;br /&gt;
    echo JModuleHelper::renderModule( $module, $attribs );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
[[Category:Tutorials]]&lt;br /&gt;
[[Category:Template Development]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=J1.5:User_Group_Access_levels_explained_in_simple_terms&amp;diff=221988</id>
		<title>J1.5:User Group Access levels explained in simple terms</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=J1.5:User_Group_Access_levels_explained_in_simple_terms&amp;diff=221988"/>
		<updated>2015-08-25T09:32:45Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: changed &amp;quot;bots&amp;quot; to &amp;quot;plugins&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{JVer|1.5}} &lt;br /&gt;
== Foreword ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that this article only applies to Joomla! version 1.5. For version 1.6 and later, please see [[ACL Tutorial for Joomla 1.6]].&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
I&#039;ve never been able to locate a &amp;quot;Plain Talk&amp;quot; version of how Joomla&#039;s access groups work, so I thought I&#039;d attempt to create one myself.  I created this in the process of doing training documentation for a client.  I hope this helps out those of you who have had a hard time finding resources to explain the concept, and I&#039;d appreciate comments and corrections.  Note: I am NOT a core dev, just a developer who wants to give something back to the community. &lt;br /&gt;
&lt;br /&gt;
== Audience ==&lt;br /&gt;
&lt;br /&gt;
This document is targeted at new users who have successfully completed a Joomla install and have accessed the Admin Backend, and upon creating their first, users wondered what the heck those Group levels mean!&lt;br /&gt;
&lt;br /&gt;
== Access Levels ==&lt;br /&gt;
&lt;br /&gt;
Joomla controls access to certain areas and features of a site through use of a basic ACL, or Access Control Level mechanism called Groups.  Certain groups have certain access level features and they are directly related to the creation, editing and publishing of content (through the Frontend and Backend interfaces) as well as to access to the Administrative (Backend) interface.&lt;br /&gt;
&lt;br /&gt;
Each group has different levels of access control and once a user is made a member of that group, they inherit those rights. Note that the &#039;Public Front-end&#039; and &#039;Public Back-end&#039; groups are merely placeholders at this point in time. They are not valid group selections at this time, but in the future, they will define the default access levels for anonymous users in the Front-end and Back-end systems.  &lt;br /&gt;
&lt;br /&gt;
The Joomla ACL has been completely reworked in Joomla 1.6 (released in Jan 2011) further information on the new ACL mechanis can be read here [http://docs.joomla.org/ACL_Tutorial_for_Joomla_1.6] and in many other places on-line.&lt;br /&gt;
&lt;br /&gt;
There are four (4) Front-end groups available:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Registered&#039;&#039;&#039; - This group allows the user to login to the Frontend interface.  Registered users can&#039;t contribute content, but this may allow them access to other areas, like a forum or download section if your site has one.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Author&#039;&#039;&#039; - This group allows a user to post content, usually via a link in the User Menu. They can submit new content, select options to show the item on the front page and select dates for publishing but they cannot directly publish any content.  When content is submitted by an Author level user, they receive the message, “Thanks for your submission. Your submission will now be reviewed before being posted to the site.”  They can edit only their own articles but only when that article has been published and is visible.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Editor&#039;&#039;&#039; - This group allows a user to post and edit any (not just their own) content item from the Frontend. They can also edit content that has not been published.  If your site uses the default installation’s menu option “News”, which is a Table List – Content Section type, Editors will see unpublished articles in the list that they can select for editing, where as an Author or Public (unregistered) user will not even see the unpublished items in the list.  Still, Editor users cannot, publish or change the publishing status of any articles, even their own.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Publisher&#039;&#039;&#039; - This group allows a user to post, edit and publish any (not just their own) content item from the Front-end.  Publishers can review all articles, edit and change publishing options but the can also determine when an article is ready for publication, making it visible to Registered, Author and the Unregistered Public (depending on what visibility was chosen in the article, of course!)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are three (3) Administration section groups that allow access to Joomla:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Manager&#039;&#039;&#039; - This group allows access to content creation and other system information from the Backend. Think of Manager users as Publishers, with Backend access.  They can log in through the Administrator interface, but their rights and access are generally restricted to content management.  They can create or edit any content, access to some Backend only features like adding, deleting and editing Sections and Categories, editing the Front Page and Menus, but they don’t have any access to the “Mechanics” of Joomla, like user management or the ability to install components or modules.  Note that if a Manager logs in through the Frontend interface, they’re treated just like a Publisher, with the same rights and access.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Administrator&#039;&#039;&#039; - This group allows access to most administration functions.  An Administrator user has all the privileges on the back end of a Manager, but they also have access to set options on, and install/delete components, modules and plugins, User Manager access and can view the site statistics.  What they cannot do however is change, edit or install Site Templates or make any changes to the sites Global configuration options.  On login through the Frontend, they are treated as Publishers, just like the Manger users.  Interesting to note; when an Administrator accesses the User Manager list, they will see all users at their access level or below; in other words they can modify any user EXCEPT a Super Administrator – in fact, they will not even see Super Administrator accounts in the list!  Also, they cannot create additional Super Administrator level accounts, only a Super Admin can do that.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Super Administrator&#039;&#039;&#039; - This group allows access to all administration functions. Only another Super Administrator can create or edit a Super Administrator user account. Full access to ALL AREAS is given to Super Administrators, and once created they cannot be as easily deleted. It might not be obvious, but you have to change the user&#039;s group to something other than Super Administrator first. Then you can delete them.&lt;br /&gt;
&lt;br /&gt;
Because of this, give a bit of thought to who you need to grant this highest level of access to. Super Admins can block the user from logging in or change the password on another SA account. Like the other Backend user accounts, SA’s are treated as Publishers when they login through the Frontend interface.&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
As mentioned previously, the Joomla ACL has been completely re-written for Joomla! 1.6 to provide new features and greater control.&lt;br /&gt;
&lt;br /&gt;
Many third-party extensions exist to extend the Joomla ACL, but due diligence should be exercised with ANY ACL extension – not only in how it affects currently available extensions for Joomla, but also how it may or may not cooperate with future releases of Joomla.&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>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Sending_email_from_extensions&amp;diff=168072</id>
		<title>Sending email from extensions</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Sending_email_from_extensions&amp;diff=168072"/>
		<updated>2015-03-31T05:24:18Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: /* Set a Sender */ joomla 3 tweak&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{version|2.5,3.1}}&lt;br /&gt;
This is an example of how to send an email from a component. You would typically put this into your component&#039;s controller.&lt;br /&gt;
=== Fetch the Mail Object ===&lt;br /&gt;
A reference to the global mail object (JMail) is fetched through the JFactory object. This is the object creating our mail.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$mailer = JFactory::getMailer();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Set a Sender ===&lt;br /&gt;
The sender of an email is set with [http://api.joomla.org/Joomla-Framework/Mail/JMail.html#setSender setSender]. The function takes an array with an email address and a name as an argument. We fetch the site&#039;s email address and name from the global configuration. These are set in the administration back-end (Global Configuration -&amp;gt; Server -&amp;gt; Mail Settings).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$config = JFactory::getConfig();&lt;br /&gt;
$sender = array( &lt;br /&gt;
    $config-&amp;gt;get( &#039;mailfrom&#039; ),&lt;br /&gt;
    $config-&amp;gt;get( &#039;fromname&#039; ) &lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$mailer-&amp;gt;setSender($sender);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In 3.1, $config-&amp;gt;getValue() should be changed to $config-&amp;gt;get()&lt;br /&gt;
&lt;br /&gt;
=== Recipient ===&lt;br /&gt;
You set the recipient of an email with the function [http://api.joomla.org/1.5/Joomla-Framework/Mail/JMail.html# addRecipient].&lt;br /&gt;
To set the email address to the currently logged in user, we fetch it from the user object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$user = JFactory::getUser();&lt;br /&gt;
$recipient = $user-&amp;gt;email;&lt;br /&gt;
&lt;br /&gt;
$mailer-&amp;gt;addRecipient($recipient);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we had multiple recipients, we would put each recipient&#039;s email address in an array.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$recipient = array( &#039;person1@domain.com&#039;, &#039;person2@domain.com&#039;, &#039;person3@domain.com&#039; );&lt;br /&gt;
&lt;br /&gt;
$mailer-&amp;gt;addRecipient($recipient);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create the Mail ===&lt;br /&gt;
We need to set a subject line and create the text body. The subject is set with [http://api.joomla.org/Joomla-Framework/Mail/JMail.html#setSubject setSubject]. &lt;br /&gt;
&lt;br /&gt;
The easy way to create an email body is as a string with plain text. Use the function [http://api.joomla.org/Joomla-Framework/Mail/JMail.html#setBody setBody] to add a message to the mail body. You can also attach a file with [http://api.joomla.org/Joomla-Framework/Mail/JMail.html#addAttachment addAttachment]. It takes a single file name or an array of file names as the argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$body   = &amp;quot;Your body string\nin double quotes if you want to parse the \nnewlines etc&amp;quot;;&lt;br /&gt;
$mailer-&amp;gt;setSubject(&#039;Your subject string&#039;);&lt;br /&gt;
$mailer-&amp;gt;setBody($body);&lt;br /&gt;
// Optional file attached&lt;br /&gt;
$mailer-&amp;gt;addAttachment(JPATH_COMPONENT.&#039;/assets/document.pdf&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you prefer to format your email in HTML, you need to tell the mailer it is HTML. This is done with [http://api.joomla.org/Unknown/PHPMailer.html#methodIsHTML IsHTML]. When sending HTML emails you should normally set the [http://api.joomla.org/Unknown/PHPMailer.html#$Encoding Encoding] to base64 in order to avoid unwanted characters in the output. The subject line and any attachments are handled as above, with the exception of images embedded in the HTML. These are taken care of with the function [http://api.joomla.org/Unknown/PHPMailer.html#AddEmbeddedImage AddEmbeddedImage].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$body   = &#039;&amp;lt;h2&amp;gt;Our mail&amp;lt;/h2&amp;gt;&#039;&lt;br /&gt;
    . &#039;&amp;lt;div&amp;gt;A message to our dear readers&#039;&lt;br /&gt;
    . &#039;&amp;lt;img src=&amp;quot;cid:logo_id&amp;quot; alt=&amp;quot;logo&amp;quot;/&amp;gt;&amp;lt;/div&amp;gt;&#039;;&lt;br /&gt;
$mailer-&amp;gt;isHTML(true);&lt;br /&gt;
$mailer-&amp;gt;Encoding = &#039;base64&#039;;&lt;br /&gt;
$mailer-&amp;gt;setBody($body);&lt;br /&gt;
// Optionally add embedded image&lt;br /&gt;
$mailer-&amp;gt;AddEmbeddedImage( JPATH_COMPONENT.&#039;/assets/logo128.jpg&#039;, &#039;logo_id&#039;, &#039;logo.jpg&#039;, &#039;base64&#039;, &#039;image/jpeg&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Normally you would leave any images on your server and refer to them with an ordinary HTML image tag, to reduce size of the mail and the time sending it.&lt;br /&gt;
&lt;br /&gt;
=== Sending the Mail ===&lt;br /&gt;
The mail is sent with the function [http://api.joomla.org/Joomla-Framework/Mail/JMail.html#Send Send]. It returns &#039;&#039;&#039;true&#039;&#039;&#039; on success or a JError object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$send = $mailer-&amp;gt;Send();&lt;br /&gt;
if ( $send !== true ) {&lt;br /&gt;
    echo &#039;Error sending email: &#039; . $send-&amp;gt;__toString();&lt;br /&gt;
} else {&lt;br /&gt;
    echo &#039;Mail sent&#039;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You would probably want to write your own error handler, if there is an error sending the mail.&lt;br /&gt;
&lt;br /&gt;
The JMail object is used for sending mail in Joomla&#039;s contact manager. See the file joomla/components/com_contact/controller.php&lt;br /&gt;
&lt;br /&gt;
===See also===&lt;br /&gt;
* [http://api.joomla.org/Joomla-Platform/JFactory.html#getMailer JFactory-&amp;gt;getMailer on api.joomla.org]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Component Development]]&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Talk:Git_for_Coders&amp;diff=158545</id>
		<title>Talk:Git for Coders</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Talk:Git_for_Coders&amp;diff=158545"/>
		<updated>2015-02-11T11:36:40Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;sovainfo: When you clone from your fork should you not remote add upstream joomla instead of joomla-developer?&lt;br /&gt;
&lt;br /&gt;
@sovainfo: yes, you are correct! I fixed it. [[User:Dextercowley|Mark Dexter]] ([[User talk:Dextercowley|talk]]) 21:43, 19 October 2012 (CDT)&lt;br /&gt;
&lt;br /&gt;
AndyGaskell: maybe this would be better split into two articles, one for command line and one for eclipse.  I found it a bit hard to follow with the two interleaved.  Just an idea, great content, thanks.&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=141499</id>
		<title>Selecting data using JDatabase</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=141499"/>
		<updated>2014-12-16T13:32:36Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: fix of previous edit&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{version|2.5,3.x}}&lt;br /&gt;
{{dablink|&#039;&#039;&#039;Version Note:&#039;&#039;&#039; Note many examples online use &amp;lt;code&amp;gt;$db-&amp;gt;query()&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;$db-&amp;gt;execute()&amp;lt;/code&amp;gt;. This was the old method in Joomla 1.5 and 2.5 and will throw a deprecated notice in Joomla 3.0+.}}&lt;br /&gt;
&lt;br /&gt;
This tutorial is split into two independent parts:&lt;br /&gt;
* Inserting, updating and removing data from the database.&lt;br /&gt;
* Selecting data from one or more tables and retrieving it in a variety of different forms&lt;br /&gt;
&lt;br /&gt;
This section of the documentation looks at selecting data from a database table and retrieving it in a variety of formats. To see the other part [[Inserting,_Updating_and_Removing_data_using_JDatabase|click here]]&lt;br /&gt;
&lt;br /&gt;
== Introduction==&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and 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 you need just two 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;
==The Query==&lt;br /&gt;
&lt;br /&gt;
Joomla&#039;s database querying changed with the introduction of Joomla 1.6. The recommended way of building database queries is through &amp;quot;query chaining&amp;quot; (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source&#039;s query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer&#039;s source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
==Selecting Records from a Single Table==&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)));&lt;br /&gt;
$query-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;));&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; LIKE &#039;. $db-&amp;gt;quote(&#039;\&#039;custom.%\&#039;&#039;));&lt;br /&gt;
$query-&amp;gt;order(&#039;ordering ASC&#039;);&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects (see later for more options on retrieving data).&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; LIKE &#039;. $db-&amp;gt;quote(&#039;\&#039;custom.%\&#039;&#039;))&lt;br /&gt;
    -&amp;gt;order(&#039;ordering ASC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
Grouping can be achieved simply too.  The following query would count the number of articles in each category&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select( array(&#039;catid&#039;, &#039;COUNT(*)&#039;) )&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;))&lt;br /&gt;
    -&amp;gt;group($db-&amp;gt;quoteName(&#039;catid&#039;));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A limit can be set to a query using &amp;quot;setLimit&amp;quot;. For example in the following query, it would return up to 10 records.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;))&lt;br /&gt;
    -&amp;gt;setLimit(&#039;10&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Selecting Records from Multiple Tables==&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery&#039;s [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with &#039;a&#039;.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
// Note by putting &#039;a&#039; as a second parameter will generate `#__content` AS `a`&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE \&#039;a%\&#039;&#039;)&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects (see later for more options on retrieving data).&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for joins:&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_innerJoin innerJoin()]&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_leftJoin leftJoin()]&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_rightJoin rightJoin()] &lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_outerJoin outerJoin()]&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;, &#039;c.*&#039;, &#039;d.*&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;join(&#039;LEFT&#039;, $db-&amp;gt;quoteName(&#039;#__user_profiles&#039;, &#039;c&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;c.user_id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;join(&#039;RIGHT&#039;, $db-&amp;gt;quoteName(&#039;#__categories&#039;, &#039;d&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;a.catid&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;d.id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE \&#039;a%\&#039;&#039;)&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
In some cases, you will also need to use the AS clause when selecting items to avoid column name conflicts. In this case, multiple select statements can be chained in conjunction with using the second parameter of $db-&amp;gt;quoteName.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(&#039;a.*&#039;))&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(&#039;b.username&#039;, &#039;username&#039;))&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(&#039;b.name&#039;, &#039;name&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE \&#039;a%\&#039;&#039;)&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A second array can also be used as the second parameter of the select statement to populate the values of the AS clause. Remember to include nulls in the second array to correspond to columns in the first array that you don&#039;t want to use the AS clause for:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;), array(&#039;&#039;, &#039;username&#039;, &#039;name&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE \&#039;a%\&#039;&#039;)&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&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;
==== loadResult() ====&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@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || 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=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
$query-&amp;gt;select(&#039;COUNT(*)&#039;);&lt;br /&gt;
$query-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;));&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;).&amp;quot; = &amp;quot;.$db-&amp;gt;quote($value));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&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 = JFactory::getDbo();&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
$query-&amp;gt;select(&#039;field_name&#039;);&lt;br /&gt;
$query-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;));&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;some_name&#039;).&amp;quot; = &amp;quot;.$db-&amp;gt;quote($some_value));&lt;br /&gt;
&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;
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@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadRow() ====&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@domain.example [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;
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;loadAssoc();&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@domain.example [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;
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@domain.example [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;$result-&amp;gt;index // e.g. $result-&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;
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@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || style=&amp;quot;background:yellow&amp;quot; | Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || style=&amp;quot;background:yellow&amp;quot; | Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadColumn() ====&lt;br /&gt;
loadColumn() 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;gt;select(&#039;name&#039;));&lt;br /&gt;
      -&amp;gt;from . . .&amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadColumn();&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;
# loadColumn() is equivalent to loadColumn(0).&lt;br /&gt;
&lt;br /&gt;
==== loadColumn($index) ====&lt;br /&gt;
loadColumn($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;gt;select(array(&#039;name&#039;, &#039;email&#039;, &#039;username&#039;));&lt;br /&gt;
      -&amp;gt;from . . .&amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadColumn(1);&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@domain.example [1] =&amp;gt; magda_h@domain.example [2] =&amp;gt; ydg@domain.example )&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;
loadColumn($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;loadColumn($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@domain.example [1] =&amp;gt; magda_h@domain.example [2] =&amp;gt; ydg@domain.example )&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;
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@domain.example || johnsmith&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadRowList() ====&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@domain.example [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@domain.example [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@domain.example [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;
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@domain.example [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@domain.example [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@domain.example [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;
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@domain.example [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@domain.example [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@domain.example [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;
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;
$row = $db-&amp;gt;loadObjectList();&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; stdClass Object ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith &lt;br /&gt;
    [email] =&amp;gt; johnsmith@domain.example [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@domain.example [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@domain.example [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;
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@domain.example [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@domain.example [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@domain.example [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;
=== Miscellaneous Result Set Methods ===&lt;br /&gt;
==== getNumRows() ====&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;execute();&lt;br /&gt;
$num_rows = $db-&amp;gt;getNumRows();&lt;br /&gt;
print_r($num_rows);&lt;br /&gt;
$result = $db-&amp;gt;loadRowList();&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 loadRowList() - 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 libraries\joomla\database\database\mysql.php on line 344&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Extension development]]&lt;br /&gt;
[[Category:Database]]&lt;br /&gt;
[[Category:JFactory]]&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=141497</id>
		<title>Selecting data using JDatabase</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=141497"/>
		<updated>2014-12-16T13:31:50Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: added info on limit&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{version|2.5,3.x}}&lt;br /&gt;
{{dablink|&#039;&#039;&#039;Version Note:&#039;&#039;&#039; Note many examples online use &amp;lt;code&amp;gt;$db-&amp;gt;query()&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;$db-&amp;gt;execute()&amp;lt;/code&amp;gt;. This was the old method in Joomla 1.5 and 2.5 and will throw a deprecated notice in Joomla 3.0+.}}&lt;br /&gt;
&lt;br /&gt;
This tutorial is split into two independent parts:&lt;br /&gt;
* Inserting, updating and removing data from the database.&lt;br /&gt;
* Selecting data from one or more tables and retrieving it in a variety of different forms&lt;br /&gt;
&lt;br /&gt;
This section of the documentation looks at selecting data from a database table and retrieving it in a variety of formats. To see the other part [[Inserting,_Updating_and_Removing_data_using_JDatabase|click here]]&lt;br /&gt;
&lt;br /&gt;
== Introduction==&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and 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 you need just two 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;
==The Query==&lt;br /&gt;
&lt;br /&gt;
Joomla&#039;s database querying changed with the introduction of Joomla 1.6. The recommended way of building database queries is through &amp;quot;query chaining&amp;quot; (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source&#039;s query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer&#039;s source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
==Selecting Records from a Single Table==&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)));&lt;br /&gt;
$query-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;));&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; LIKE &#039;. $db-&amp;gt;quote(&#039;\&#039;custom.%\&#039;&#039;));&lt;br /&gt;
$query-&amp;gt;order(&#039;ordering ASC&#039;);&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects (see later for more options on retrieving data).&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; LIKE &#039;. $db-&amp;gt;quote(&#039;\&#039;custom.%\&#039;&#039;))&lt;br /&gt;
    -&amp;gt;order(&#039;ordering ASC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
Grouping can be achieved simply too.  The following query would count the number of articles in each category&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select( array(&#039;catid&#039;, &#039;COUNT(*)&#039;) )&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;))&lt;br /&gt;
    -&amp;gt;group($db-&amp;gt;quoteName(&#039;catid&#039;));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A limit can be set to a query using &amp;quot;setLimit&amp;quot;. For example in the following query, it would return up to 10 records.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;))&lt;br /&gt;
    $query-&amp;gt;setLimit(&#039;10&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Selecting Records from Multiple Tables==&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery&#039;s [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with &#039;a&#039;.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
// Note by putting &#039;a&#039; as a second parameter will generate `#__content` AS `a`&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE \&#039;a%\&#039;&#039;)&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects (see later for more options on retrieving data).&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for joins:&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_innerJoin innerJoin()]&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_leftJoin leftJoin()]&lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_rightJoin rightJoin()] &lt;br /&gt;
* [http://api.joomla.org/cms-3/classes/JDatabaseQuery.html#method_outerJoin outerJoin()]&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;, &#039;c.*&#039;, &#039;d.*&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;join(&#039;LEFT&#039;, $db-&amp;gt;quoteName(&#039;#__user_profiles&#039;, &#039;c&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;c.user_id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;join(&#039;RIGHT&#039;, $db-&amp;gt;quoteName(&#039;#__categories&#039;, &#039;d&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;a.catid&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;d.id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE \&#039;a%\&#039;&#039;)&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
In some cases, you will also need to use the AS clause when selecting items to avoid column name conflicts. In this case, multiple select statements can be chained in conjunction with using the second parameter of $db-&amp;gt;quoteName.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(&#039;a.*&#039;))&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(&#039;b.username&#039;, &#039;username&#039;))&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(&#039;b.name&#039;, &#039;name&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE \&#039;a%\&#039;&#039;)&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A second array can also be used as the second parameter of the select statement to populate the values of the AS clause. Remember to include nulls in the second array to correspond to columns in the first array that you don&#039;t want to use the AS clause for:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;), array(&#039;&#039;, &#039;username&#039;, &#039;name&#039;))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE \&#039;a%\&#039;&#039;)&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&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;
==== loadResult() ====&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@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || 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=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
$query-&amp;gt;select(&#039;COUNT(*)&#039;);&lt;br /&gt;
$query-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;));&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;).&amp;quot; = &amp;quot;.$db-&amp;gt;quote($value));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&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 = JFactory::getDbo();&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
$query-&amp;gt;select(&#039;field_name&#039;);&lt;br /&gt;
$query-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;));&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;some_name&#039;).&amp;quot; = &amp;quot;.$db-&amp;gt;quote($some_value));&lt;br /&gt;
&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;
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@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadRow() ====&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@domain.example [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;
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;loadAssoc();&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@domain.example [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;
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@domain.example [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;$result-&amp;gt;index // e.g. $result-&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;
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@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || style=&amp;quot;background:yellow&amp;quot; | Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || style=&amp;quot;background:yellow&amp;quot; | Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadColumn() ====&lt;br /&gt;
loadColumn() 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;gt;select(&#039;name&#039;));&lt;br /&gt;
      -&amp;gt;from . . .&amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadColumn();&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;
# loadColumn() is equivalent to loadColumn(0).&lt;br /&gt;
&lt;br /&gt;
==== loadColumn($index) ====&lt;br /&gt;
loadColumn($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;gt;select(array(&#039;name&#039;, &#039;email&#039;, &#039;username&#039;));&lt;br /&gt;
      -&amp;gt;from . . .&amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadColumn(1);&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@domain.example [1] =&amp;gt; magda_h@domain.example [2] =&amp;gt; ydg@domain.example )&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;
loadColumn($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;loadColumn($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@domain.example [1] =&amp;gt; magda_h@domain.example [2] =&amp;gt; ydg@domain.example )&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;
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@domain.example || johnsmith&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadRowList() ====&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@domain.example [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@domain.example [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@domain.example [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;
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@domain.example [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@domain.example [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@domain.example [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;
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@domain.example [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@domain.example [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@domain.example [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;
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;
$row = $db-&amp;gt;loadObjectList();&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; stdClass Object ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith &lt;br /&gt;
    [email] =&amp;gt; johnsmith@domain.example [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@domain.example [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@domain.example [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;
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@domain.example [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@domain.example [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@domain.example [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;
=== Miscellaneous Result Set Methods ===&lt;br /&gt;
==== getNumRows() ====&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;execute();&lt;br /&gt;
$num_rows = $db-&amp;gt;getNumRows();&lt;br /&gt;
print_r($num_rows);&lt;br /&gt;
$result = $db-&amp;gt;loadRowList();&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 loadRowList() - 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 libraries\joomla\database\database\mysql.php on line 344&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Extension development]]&lt;br /&gt;
[[Category:Database]]&lt;br /&gt;
[[Category:JFactory]]&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Archived_talk:Adding_custom_fields_to_the_article_component&amp;diff=106727</id>
		<title>Archived talk:Adding custom fields to the article component</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Archived_talk:Adding_custom_fields_to_the_article_component&amp;diff=106727"/>
		<updated>2014-01-06T20:10:58Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Great tutorial, will the patch be soon integrated to Joomla! packages ?&lt;br /&gt;
I had to install the patch in a Joomla 2.5.8 site in order to make the plugin work and I wonder if I will have to install the patch again after each update.&lt;br /&gt;
&lt;br /&gt;
Thanks for your job anyway.&lt;br /&gt;
&lt;br /&gt;
Thierry&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Really useful tutorial, thanks.  I just tried it on Joomla 3.1 and it doesn&#039;t work.  I&#039;ll see if I can figure out what the issues are.&lt;br /&gt;
&lt;br /&gt;
Andy G&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=User:AndyGaskell&amp;diff=106263</id>
		<title>User:AndyGaskell</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=User:AndyGaskell&amp;diff=106263"/>
		<updated>2013-12-06T13:34:44Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: adding blurb&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;My name is AndyGaskell and if you want to get in touch with me, post on my &#039;&#039;&#039;[[User_talk:{{PAGENAME}}|talk page]]&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
I&#039;m a web developer, LAMP, AJAX etc. I&#039;ve worked in design and IT too. Been writing code for 20 years :)&lt;br /&gt;
&lt;br /&gt;
I work at SSOFB in Aberdeen Scotland. I&#039;ve also live in London, Edinburgh, Sydney and Glasgow.&lt;br /&gt;
&lt;br /&gt;
There are more Linux devices in our house than Windows, (5 v 2). I built our TV, it runs Linux. My kids know what a PCB is and try to fix their broken toys.&lt;br /&gt;
&lt;br /&gt;
I support Crystal Palace FC, as I grew up in South London.&lt;br /&gt;
&lt;br /&gt;
==My testing subpages==&lt;br /&gt;
&amp;lt;splist/&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=User:AndyGaskell&amp;diff=106262</id>
		<title>User:AndyGaskell</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=User:AndyGaskell&amp;diff=106262"/>
		<updated>2013-12-06T13:32:58Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: Created page with &amp;quot;{{subst:Newuser}}&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;My name is AndyGaskell and if you want to get in touch with me, post on my &#039;&#039;&#039;[[User_talk:{{PAGENAME}}|talk page]]&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
==My testing subpages==&lt;br /&gt;
&amp;lt;splist/&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=106261</id>
		<title>Selecting data using JDatabase</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=106261"/>
		<updated>2013-12-06T13:32:22Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: /* Selecting Records from a Single Table */ wording tweak from previous edit&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{version|2.5,3.x}}&lt;br /&gt;
{{dablink|&#039;&#039;&#039;Version Note:&#039;&#039;&#039; While this document pertains to Joomla! 2.5 and 3.x, &amp;lt;code&amp;gt;$db-&amp;gt;query()&amp;lt;/code&amp;gt; throws a deprecated notice in Joomla 3.0+. In that case, change &amp;lt;code&amp;gt;$db-&amp;gt;query()&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;$db-&amp;gt;execute()&amp;lt;/code&amp;gt;. However note &amp;lt;code&amp;gt;$db-&amp;gt;execute()&amp;lt;/code&amp;gt; does not work in Joomla 2.5.}}&lt;br /&gt;
&lt;br /&gt;
This tutorial is split into two independent parts:&lt;br /&gt;
* Inserting, updating and removing data from the database.&lt;br /&gt;
* Selecting data from one or more tables and retrieving it in a variety of different forms&lt;br /&gt;
&lt;br /&gt;
This section of the documentation looks at selecting data from a database table and retrieving it in a variety of formats. To see the other part [[Inserting,_Updating_and_Removing_data_using_JDatabase|click here]]&lt;br /&gt;
&lt;br /&gt;
== Introduction==&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and 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 you need just two 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;
==The Query==&lt;br /&gt;
&lt;br /&gt;
Joomla&#039;s database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source&#039;s query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer&#039;s source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
==Selecting Records from a Single Table==&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)));&lt;br /&gt;
$query-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;));&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; LIKE &#039;. $db-&amp;gt;quote(&#039;\&#039;custom.%\&#039;&#039;));&lt;br /&gt;
$query-&amp;gt;order(&#039;ordering ASC&#039;);&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects (see later for more options on retrieving data).&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; LIKE &#039;. $db-&amp;gt;quote(&#039;\&#039;custom.%\&#039;&#039;))&lt;br /&gt;
    -&amp;gt;order(&#039;ordering ASC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
Grouping can be achieved simply too.  The following query would count the number of articles in each category&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select( array(&#039;catid&#039;, &#039;COUNT(*)&#039;) )&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;))&lt;br /&gt;
    -&amp;gt;group($db-&amp;gt;quoteName(&#039;catid&#039;));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Selecting Records from Multiple Tables==&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery&#039;s [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with &#039;a&#039;.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
// Note by putting &#039;a&#039; as a second parameter will generate `#__content` AS `a`&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE \&#039;a%\&#039;&#039;)&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects (see later for more options on retrieving data).&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;, &#039;c.*&#039;, &#039;d.*&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;join(&#039;LEFT&#039;, $db-&amp;gt;quoteName(&#039;#__user_profiles&#039;, &#039;c&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;c.user_id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;join(&#039;RIGHT&#039;, $db-&amp;gt;quoteName(&#039;#__categories&#039;, &#039;d&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;a.catid&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;d.id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE \&#039;a%\&#039;&#039;)&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&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;
==== loadResult() ====&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@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || 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=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
$query-&amp;gt;select(&#039;COUNT(*)&#039;);&lt;br /&gt;
$query-&amp;gt;from($db-&amp;gt;quoteName&#039;#__my_table&#039;);&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;).&amp;quot; = &amp;quot;.$db-&amp;gt;quote($value));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&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 = JFactory::getDbo();&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
$query-&amp;gt;select(&#039;field_name&#039;);&lt;br /&gt;
$query-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;));&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;some_name&#039;).&amp;quot; = &amp;quot;.$db-&amp;gt;quote($some_value));&lt;br /&gt;
&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;
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@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadRow() ====&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@domain.example [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;
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;loadAssoc();&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@domain.example [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;
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@domain.example [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;$result-&amp;gt;index // e.g. $result-&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;
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@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || style=&amp;quot;background:yellow&amp;quot; | Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || style=&amp;quot;background:yellow&amp;quot; | Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadColumn() ====&lt;br /&gt;
loadColumn() 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;gt;select(&#039;name&#039;));&lt;br /&gt;
      -&amp;gt;from . . .&amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadColumn();&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;
# loadColumn() is equivalent to loadColumn(0).&lt;br /&gt;
&lt;br /&gt;
==== loadColumn($index) ====&lt;br /&gt;
loadColumn($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;gt;select(array(&#039;name&#039;, &#039;email&#039;, &#039;username&#039;));&lt;br /&gt;
      -&amp;gt;from . . .&amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadColumn(1);&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@domain.example [1] =&amp;gt; magda_h@domain.example [2] =&amp;gt; ydg@domain.example )&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;
loadColumn($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;loadColumn($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@domain.example [1] =&amp;gt; magda_h@domain.example [2] =&amp;gt; ydg@domain.example )&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;
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@domain.example || johnsmith&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadRowList() ====&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@domain.example [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@domain.example [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@domain.example [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;
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@domain.example [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@domain.example [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@domain.example [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;
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@domain.example [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@domain.example [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@domain.example [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;
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;
$row = $db-&amp;gt;loadObjectList();&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; stdClass Object ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith &lt;br /&gt;
    [email] =&amp;gt; johnsmith@domain.example [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@domain.example [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@domain.example [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;
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@domain.example [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@domain.example [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@domain.example [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;
=== Miscellaneous Result Set Methods ===&lt;br /&gt;
==== getNumRows() ====&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;loadRowList();&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 loadRowList() - 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 libraries\joomla\database\database\mysql.php on line 344&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=106260</id>
		<title>Selecting data using JDatabase</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=106260"/>
		<updated>2013-12-06T13:31:31Z</updated>

		<summary type="html">&lt;p&gt;AndyGaskell: added not and code re grouping&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{version|2.5,3.x}}&lt;br /&gt;
{{dablink|&#039;&#039;&#039;Version Note:&#039;&#039;&#039; While this document pertains to Joomla! 2.5 and 3.x, &amp;lt;code&amp;gt;$db-&amp;gt;query()&amp;lt;/code&amp;gt; throws a deprecated notice in Joomla 3.0+. In that case, change &amp;lt;code&amp;gt;$db-&amp;gt;query()&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;$db-&amp;gt;execute()&amp;lt;/code&amp;gt;. However note &amp;lt;code&amp;gt;$db-&amp;gt;execute()&amp;lt;/code&amp;gt; does not work in Joomla 2.5.}}&lt;br /&gt;
&lt;br /&gt;
This tutorial is split into two independent parts:&lt;br /&gt;
* Inserting, updating and removing data from the database.&lt;br /&gt;
* Selecting data from one or more tables and retrieving it in a variety of different forms&lt;br /&gt;
&lt;br /&gt;
This section of the documentation looks at selecting data from a database table and retrieving it in a variety of formats. To see the other part [[Inserting,_Updating_and_Removing_data_using_JDatabase|click here]]&lt;br /&gt;
&lt;br /&gt;
== Introduction==&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and 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 you need just two 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;
==The Query==&lt;br /&gt;
&lt;br /&gt;
Joomla&#039;s database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source&#039;s query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer&#039;s source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
==Selecting Records from a Single Table==&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)));&lt;br /&gt;
$query-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;));&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; LIKE &#039;. $db-&amp;gt;quote(&#039;\&#039;custom.%\&#039;&#039;));&lt;br /&gt;
$query-&amp;gt;order(&#039;ordering ASC&#039;);&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects (see later for more options on retrieving data).&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;user_id&#039;, &#039;profile_key&#039;, &#039;profile_value&#039;, &#039;ordering&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__user_profiles&#039;))&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;profile_key&#039;) . &#039; LIKE &#039;. $db-&amp;gt;quote(&#039;\&#039;custom.%\&#039;&#039;))&lt;br /&gt;
    -&amp;gt;order(&#039;ordering ASC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
Grouping can be achieved simply too.  The following query would count all articles in each category&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select( array(&#039;catid&#039;, &#039;COUNT(*)&#039;) )&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;))&lt;br /&gt;
    -&amp;gt;group($db-&amp;gt;quoteName(&#039;catid&#039;));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Selecting Records from Multiple Tables==&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery&#039;s [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with &#039;a&#039;.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
// Note by putting &#039;a&#039; as a second parameter will generate `#__content` AS `a`&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE \&#039;a%\&#039;&#039;)&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects (see later for more options on retrieving data).&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select($db-&amp;gt;quoteName(array(&#039;a.*&#039;, &#039;b.username&#039;, &#039;b.name&#039;, &#039;c.*&#039;, &#039;d.*&#039;)))&lt;br /&gt;
    -&amp;gt;from($db-&amp;gt;quoteName(&#039;#__content&#039;, &#039;a&#039;))&lt;br /&gt;
    -&amp;gt;join(&#039;INNER&#039;, $db-&amp;gt;quoteName(&#039;#__users&#039;, &#039;b&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;a.created_by&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;join(&#039;LEFT&#039;, $db-&amp;gt;quoteName(&#039;#__user_profiles&#039;, &#039;c&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;b.id&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;c.user_id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;join(&#039;RIGHT&#039;, $db-&amp;gt;quoteName(&#039;#__categories&#039;, &#039;d&#039;) . &#039; ON (&#039; . $db-&amp;gt;quoteName(&#039;a.catid&#039;) . &#039; = &#039; . $db-&amp;gt;quoteName(&#039;d.id&#039;) . &#039;)&#039;)&lt;br /&gt;
    -&amp;gt;where($db-&amp;gt;quoteName(&#039;b.username&#039;) . &#039; LIKE \&#039;a%\&#039;&#039;)&lt;br /&gt;
    -&amp;gt;order($db-&amp;gt;quoteName(&#039;a.created&#039;) . &#039; DESC&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&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;
==== loadResult() ====&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@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || 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=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
$query-&amp;gt;select(&#039;COUNT(*)&#039;);&lt;br /&gt;
$query-&amp;gt;from($db-&amp;gt;quoteName&#039;#__my_table&#039;);&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;name&#039;).&amp;quot; = &amp;quot;.$db-&amp;gt;quote($value));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&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 = JFactory::getDbo();&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
$query-&amp;gt;select(&#039;field_name&#039;);&lt;br /&gt;
$query-&amp;gt;from($db-&amp;gt;quoteName(&#039;#__my_table&#039;));&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;some_name&#039;).&amp;quot; = &amp;quot;.$db-&amp;gt;quote($some_value));&lt;br /&gt;
&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;
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@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadRow() ====&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@domain.example [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;
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;loadAssoc();&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@domain.example [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;
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@domain.example [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;$result-&amp;gt;index // e.g. $result-&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;
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@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || style=&amp;quot;background:yellow&amp;quot; | Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || style=&amp;quot;background:yellow&amp;quot; | Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadColumn() ====&lt;br /&gt;
loadColumn() 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;gt;select(&#039;name&#039;));&lt;br /&gt;
      -&amp;gt;from . . .&amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadColumn();&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;
# loadColumn() is equivalent to loadColumn(0).&lt;br /&gt;
&lt;br /&gt;
==== loadColumn($index) ====&lt;br /&gt;
loadColumn($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;gt;select(array(&#039;name&#039;, &#039;email&#039;, &#039;username&#039;));&lt;br /&gt;
      -&amp;gt;from . . .&amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadColumn(1);&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@domain.example [1] =&amp;gt; magda_h@domain.example [2] =&amp;gt; ydg@domain.example )&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;
loadColumn($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;loadColumn($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@domain.example [1] =&amp;gt; magda_h@domain.example [2] =&amp;gt; ydg@domain.example )&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;
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@domain.example || johnsmith&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadRowList() ====&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@domain.example [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@domain.example [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@domain.example [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;
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@domain.example [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@domain.example [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@domain.example [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;
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@domain.example [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@domain.example [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@domain.example [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;
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;
$row = $db-&amp;gt;loadObjectList();&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; stdClass Object ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith &lt;br /&gt;
    [email] =&amp;gt; johnsmith@domain.example [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@domain.example [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@domain.example [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;
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@domain.example [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@domain.example [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@domain.example [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;
=== Miscellaneous Result Set Methods ===&lt;br /&gt;
==== getNumRows() ====&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;loadRowList();&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 loadRowList() - 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 libraries\joomla\database\database\mysql.php on line 344&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>AndyGaskell</name></author>
	</entry>
</feed>