<?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=Mickmackusa</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=Mickmackusa"/>
	<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/Special:Contributions/Mickmackusa"/>
	<updated>2026-08-08T21:44:21Z</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=635119</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=635119"/>
		<updated>2019-10-19T06:30:29Z</updated>

		<summary type="html">&lt;p&gt;Mickmackusa: implemented the chained syntax recommended earlier on the same page, added spaces around concatenating dots&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;
==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>Mickmackusa</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=635118</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=635118"/>
		<updated>2019-10-19T06:22:18Z</updated>

		<summary type="html">&lt;p&gt;Mickmackusa: adding and removing spaces in snippets&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;
==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-&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;
&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-&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;
&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>Mickmackusa</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=635117</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=635117"/>
		<updated>2019-10-19T06:20:37Z</updated>

		<summary type="html">&lt;p&gt;Mickmackusa: it is entirely useless to add parentheses to ON statements that only have one expression&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;
==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-&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;
&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-&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;
&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>Mickmackusa</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Selecting_data_using_JDatabase&amp;diff=635116</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=635116"/>
		<updated>2019-10-19T06:11:55Z</updated>

		<summary type="html">&lt;p&gt;Mickmackusa: fixed redundant/incorrect single quotes within quote()&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;) . &#039;)&#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;) . &#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; . $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;) . &#039;)&#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;) . &#039;)&#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;
==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-&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;
&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-&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;
&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>Mickmackusa</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Joomla_and_MySQL_8&amp;diff=635115</id>
		<title>Joomla and MySQL 8</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Joomla_and_MySQL_8&amp;diff=635115"/>
		<updated>2019-10-19T06:00:34Z</updated>

		<summary type="html">&lt;p&gt;Mickmackusa: improved English&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;&lt;br /&gt;
==MySQL default authentication plugin issue== &amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:2--&amp;gt; It&#039;s not possible to connect to a MySQL 8 Database using Joomla 3.8, 3.9 or 4.0. The reason is that MySQL 8 has a lot of changes under the hood. One change that affects Joomla is the default authentication plugin which is &amp;lt;tt&amp;gt;sha256_password&amp;lt;/tt&amp;gt; instead of &amp;lt;tt&amp;gt;mysql_native_password&amp;lt;/tt&amp;gt;. The native PHP MySQL-Driver don&#039;t support MySQL 8 with this plugin yet other programming languages like GO or PERL are struggling too. [https://github.com/php/php-src/commit/d6e81f0bfd0cb90586dd83d4fd47a4302605261a PHP 7.3 (alpha)] is supporting MySQL 8 though.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==Workaround to get Joomla working with MySQL 8== &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;
Fortunately there is a workaround! We can use the &amp;lt;tt&amp;gt;mysql_native_password&amp;lt;/tt&amp;gt; default authentication plugin for MySQL.&lt;br /&gt;
We need to open our configuration file &amp;lt;tt&amp;gt;sudo nano /etc/my.cnf&amp;lt;/tt&amp;gt; (Please note that your file may be under a different directory) and add the following configuration:&amp;lt;/translate&amp;gt; &lt;br /&gt;
&amp;lt;source lang=&amp;quot;ini&amp;quot;&amp;gt;&lt;br /&gt;
[mysqld]&lt;br /&gt;
default-authentication-plugin=mysql_native_password&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:5--&amp;gt; If you don&#039;t have access to your config file then you can update your user as follows:&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
ALTER USER &#039;username&#039;@&#039;localhost&#039; IDENTIFIED WITH mysql_native_password BY &#039;password&#039;;&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:6--&amp;gt; Replace username with the name of the user account and password with the password belonging to the account. Restart MySQL and you are done ...well, only if you have Joomla 3.8 or 3.9 installed.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:7--&amp;gt; If you want to work with Joomla 4.0, you have to do some extra work, because the administration dashboard is blank after the installation with Joomla 4.0 and MySQL 8.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
Fortunately there is a fix for that too! &lt;br /&gt;
MySQL 8 is returning &amp;lt;tt&amp;gt;Incorrect date value: &#039;0000-00-00&#039;&amp;lt;/tt&amp;gt; after running following insertion from the installation file &amp;lt;tt&amp;gt;/installation/sql/mysql/joomla.sql&amp;lt;/tt&amp;gt;.&amp;lt;/translate&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:9--&amp;gt; The following query must be run to fix this. Replace #_ with your table prefix.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=sql&amp;gt;&lt;br /&gt;
UPDATE `#__modules` SET `checked_out_time` = &#039;1000-01-01 00:00:00&#039;, `publish_up` = &#039;1000-01-01 00:00:00&#039;, `publish_down` = &#039;1000-01-01 00:00:00&#039;;&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; This is happening because since MySQL 5.7, MySQL stops supporting zeros value in date / datetime.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==How MySQL default authentication plugin works== &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; The advantage of &amp;lt;tt&amp;gt;mysql_native_password&amp;lt;/tt&amp;gt; is that it supports the challenge-response mechanism which is very quick and does not require encrypted connection. However, &amp;lt;tt&amp;gt;mysql_native_password&amp;lt;/tt&amp;gt; relies on SHA1 algorithm and NIST has recommended to stop using it.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:13--&amp;gt; Further, if two user accounts use the same password, &amp;lt;tt&amp;gt;mysql_native_password&amp;lt;/tt&amp;gt; transformation is the same in the mysql.user table. Although the hash does not expose information about the actual password, it still tells which two users use the same password. To avoid that, a salt should be used. A salt is basically a random number that is used as one of the parameters to cryptographic hash functions used to transform user passwords. Since a salt is random and different for each execution, even if two users use the same passwords, the end result of transformation would look very different.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
Since MySQL 5.6, sha256_password authentication plugin is supported. It uses multiple rounds of SHA256 hash on a salted password to make sure that the hash transformation is more secure. However, it requires either encrypted connections or support for an RSA key pair. So, while password security is stronger, secure connections and multiple rounds of hash transformations require more time in the authentication process.&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&amp;lt;!--T:15--&amp;gt; caching_sha2_password tries to combine the best of both worlds.&amp;lt;/translate&amp;gt; &amp;lt;ref&amp;gt;https://mysqlserverteam.com/mysql-8-0-4-new-default-authentication-plugin-caching_sha2_password/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
[[Category:Server configurations{{#translation:}}]]&lt;br /&gt;
[[Category:Installation{{#translation:}}]]&lt;br /&gt;
[[Category:Tutorials{{#translation:}}]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mickmackusa</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=J3.x:Developing_a_MVC_Component/Adding_ACL/en&amp;diff=635114</id>
		<title>J3.x:Developing a MVC Component/Adding ACL/en</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=J3.x:Developing_a_MVC_Component/Adding_ACL/en&amp;diff=635114"/>
		<updated>2019-10-19T05:51:13Z</updated>

		<summary type="html">&lt;p&gt;Mickmackusa: improved English&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;
{{review}}&lt;br /&gt;
{{:J3.1:Developing a MVC Component/en}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This tutorial is part of the [[S:MyLanguage/J3.2:Developing a MVC Component | Developing a MVC Component for Joomla! 3.2]] tutorial. You are encouraged to read the previous parts of the tutorial before reading this.&lt;br /&gt;
&lt;br /&gt;
== Adding Access Control ==&lt;br /&gt;
With Joomla!&#039;s Access Control we can define which user groups are allowed or denied specific actions in your component. In this example, we use actions that are defined in the core. For the component as a whole: core.admin (access to the configuration) and core.manage (access to the backend). And at various levels actions like create, delete and edit. Besides those core actions, you can define your own actions, but that is often not necessary and is not shown in this example. View/Read Access is not managed via those actions but with View Access Levels; see general documentation about Joomla!&#039;s ACL for that. &lt;br /&gt;
&lt;br /&gt;
In the #__assets table, the actual list is stored: which user groups are allowed or denied specific actions on specific resources (assets). This is the implementation of the Access Control List (ACL). &lt;br /&gt;
&lt;br /&gt;
In this article, we will show how to add and use access permissions at several levels of granularity: for your component as a whole, for categories and for individual items.&lt;br /&gt;
&lt;br /&gt;
Note: In this HelloWorld example we are working in the backend, so the only access level available are &#039;&#039;administrator&#039;&#039; and &#039;&#039;superuser&#039;&#039;.&lt;br /&gt;
To test this tutorial, first create a new administrator user and then set its permissions (working as superuser).&lt;br /&gt;
After logging in as administrator you will see the changes.&lt;br /&gt;
&lt;br /&gt;
== Minimal ACL requirements at the component level ==&lt;br /&gt;
There are 2 actions that need to be defined at the component level for a Joomla! 2.5+ component to offer basic ACL support:&lt;br /&gt;
* &#039;&#039;&#039;Configure&#039;&#039;&#039; (core.admin): which groups are allowed to configure the component level permissions via the &#039;Options&#039; toolbar button?&lt;br /&gt;
* &#039;&#039;&#039;Access Component&#039;&#039;&#039; (core.manage): which groups are allowed to access the component&#039;s backend?&lt;br /&gt;
&lt;br /&gt;
This basic ACL support is done in 4 simple steps:&lt;br /&gt;
* [[#Add_the_2_minimal_component_level_actions_to_access.xml|Add the 2 minimal component level actions to access.xml]]&lt;br /&gt;
* [[#Add_the_permissions_fieldset_to_config.xml|Add the permissions fieldset to config.xml]]&lt;br /&gt;
* [[#Add_the_.27Options.27_toolbar_button_when_user_is_authorised_for_it|Add the &#039;Options&#039; toolbar button]]&lt;br /&gt;
* [[#Restrict_the_access_to_the_component.27s_backend_to_authorised_usergroups|Restrict the access to the component&#039;s backend]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Add the 2 minimal component level actions to access.xml ===&lt;br /&gt;
A minimal ACL &amp;lt;/tt&amp;gt;access.xml&amp;lt;/tt&amp;gt; would consist of only those 2 basic actions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;Basic admin/access.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;access component=&amp;quot;com_helloworld&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;section name=&amp;quot;component&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;action name=&amp;quot;core.admin&amp;quot; title=&amp;quot;JACTION_ADMIN&amp;quot; description=&amp;quot;JACTION_ADMIN_COMPONENT_DESC&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;action name=&amp;quot;core.manage&amp;quot; title=&amp;quot;JACTION_MANAGE&amp;quot; description=&amp;quot;JACTION_MANAGE_COMPONENT_DESC&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/section&amp;gt;&lt;br /&gt;
&amp;lt;/access&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_categories#admin/access.xml|admin/access.xml]]&#039;&#039; for the current and more elaborate version.&lt;br /&gt;
&lt;br /&gt;
=== Add the permissions fieldset to config.xml ===&lt;br /&gt;
Add the following permissions fieldset to &amp;lt;tt&amp;gt;admin/config.xml&amp;lt;/tt&amp;gt; in order to be able to set our component level permissions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;fieldset&lt;br /&gt;
		name=&amp;quot;permissions&amp;quot;&lt;br /&gt;
		label=&amp;quot;JCONFIG_PERMISSIONS_LABEL&amp;quot;&lt;br /&gt;
		description=&amp;quot;JCONFIG_PERMISSIONS_DESC&amp;quot;&lt;br /&gt;
	&amp;gt;&lt;br /&gt;
		&amp;lt;field&lt;br /&gt;
			name=&amp;quot;rules&amp;quot;&lt;br /&gt;
			type=&amp;quot;rules&amp;quot;&lt;br /&gt;
			label=&amp;quot;JCONFIG_PERMISSIONS_LABEL&amp;quot;&lt;br /&gt;
			class=&amp;quot;inputbox&amp;quot;&lt;br /&gt;
			validate=&amp;quot;rules&amp;quot;&lt;br /&gt;
			filter=&amp;quot;rules&amp;quot;&lt;br /&gt;
			component=&amp;quot;com_helloworld&amp;quot;&lt;br /&gt;
			section=&amp;quot;component&amp;quot;&lt;br /&gt;
		/&amp;gt;&lt;br /&gt;
	&amp;lt;/fieldset&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See the [[#admin.2Fconfig.xml|more elaborate config.xml example]] further downwards for the exact place where to insert this code.&lt;br /&gt;
&lt;br /&gt;
=== Add the &#039;Options&#039; toolbar button when user is authorised for it ===&lt;br /&gt;
In the &amp;lt;tt&amp;gt;admin/views/helloworlds/view.html.php&amp;lt;/tt&amp;gt; file you can add the following code to check if the user can edit the preferences:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;2-3,5&amp;quot;&amp;gt;&lt;br /&gt;
    // Options button.&lt;br /&gt;
    if (JFactory::getUser()-&amp;gt;authorise(&#039;core.admin&#039;, &#039;com_helloworld&#039;)) &lt;br /&gt;
    {&lt;br /&gt;
	JToolBarHelper::preferences(&#039;com_helloworld&#039;);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See further downwards for a [[#admin/views/helloworlds/view.html.php|more elaborated example of &#039;&#039;admin/views/helloworlds/view.html.php&#039;&#039;]] where this &#039;&#039;JToolBarHelper::preferences(&#039;com_helloworld&#039;)&#039;&#039; is done in an addToolBar()-method together with the other toolbar buttons and the &#039;&#039;JUser-&amp;gt;authorise()&#039;&#039;-check is done with JHelperContent, resulting in the $canDo-property.&lt;br /&gt;
&lt;br /&gt;
=== Restrict the access to the component&#039;s backend to authorised usergroups ===&lt;br /&gt;
To control the access to the backend of the component add the following lines to the &amp;lt;tt&amp;gt;admin/helloworld.php&amp;lt;/tt&amp;gt; entry-file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Access check: is this user allowed to access the backend of this component?&lt;br /&gt;
if (!JFactory::getUser()-&amp;gt;authorise(&#039;core.manage&#039;, &#039;com_helloworld&#039;)) &lt;br /&gt;
{&lt;br /&gt;
	throw new Exception(JText::_(&#039;JERROR_ALERTNOAUTHOR&#039;));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See further downwards for the [[#admin/helloworld.php|whole code of the &#039;&#039;admin/helloworld.php&#039;&#039; file]].&lt;br /&gt;
&lt;br /&gt;
== Adding more actions, also at category level and item level ==&lt;br /&gt;
When adding more actions and more levels, the above described 4 steps are done too:&lt;br /&gt;
* [[#Describing_the_actions_you_want_to_control_the_access_to|Add the actions to access.xml; here we can add more actions and levels]]&lt;br /&gt;
* [[#Adding_the_setting_of_permissions_in_the_component.27s_Preferences|Add the permissions-fieldset to config.xml]]&lt;br /&gt;
* [[#Displaying_only_the_right_toolbar_buttons|Add the &#039;Options&#039; toolbar button]]&lt;br /&gt;
* [[#Restricting_access_to_the_component|Restrict the access to the component&#039;s backend&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
In addition we also have to do the following steps:&lt;br /&gt;
* [[#Add_the_asset_id_column_to_the_database_table|Add an asset_id to the item&#039;s database table for item level access control]]&lt;br /&gt;
* [[#Setting_the_permission_values_in_the_assets_table|Store the permissions in the assets table. Especially take care of setting the asset_id of the parent-asset]]&lt;br /&gt;
* [[#Showing_the_setting_of_permissions_on_the_item_level|Make the settings of the permissions at the item level editable]]&lt;br /&gt;
* [[#Adding_language_strings|Add some language strings]]&lt;br /&gt;
&lt;br /&gt;
=== Describing the actions you want to control the access to ===&lt;br /&gt;
Each component (or part of it) has its own set of permissions that can be controlled. They are described in an &amp;lt;tt&amp;gt;access.xml&amp;lt;/tt&amp;gt; file located at the root of the &#039;&#039;admin&#039;&#039; folder. In this helloworld-example the actions to which access is controlled are divided in three sections: at the component level, the category level and the item level. An &#039;item&#039; is called a &#039;message&#039; in our example component, hence the name of the third section.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;admin/access.xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;admin/access.xml&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; highlight=&amp;quot;10-16&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;access component=&amp;quot;com_helloworld&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;section name=&amp;quot;component&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;action name=&amp;quot;core.admin&amp;quot; title=&amp;quot;JACTION_ADMIN&amp;quot; description=&amp;quot;JACTION_ADMIN_COMPONENT_DESC&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;action name=&amp;quot;core.manage&amp;quot; title=&amp;quot;JACTION_MANAGE&amp;quot; description=&amp;quot;JACTION_MANAGE_COMPONENT_DESC&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;action name=&amp;quot;core.create&amp;quot; title=&amp;quot;JACTION_CREATE&amp;quot; description=&amp;quot;JACTION_CREATE_COMPONENT_DESC&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;action name=&amp;quot;core.delete&amp;quot; title=&amp;quot;JACTION_DELETE&amp;quot; description=&amp;quot;JACTION_DELETE_COMPONENT_DESC&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;action name=&amp;quot;core.edit&amp;quot; title=&amp;quot;JACTION_EDIT&amp;quot; description=&amp;quot;JACTION_EDIT_COMPONENT_DESC&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/section&amp;gt;&lt;br /&gt;
	&amp;lt;section name=&amp;quot;category&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;action name=&amp;quot;core.create&amp;quot; title=&amp;quot;JACTION_CREATE&amp;quot; description=&amp;quot;COM_CATEGORIES_ACCESS_CREATE_DESC&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;action name=&amp;quot;core.delete&amp;quot; title=&amp;quot;JACTION_DELETE&amp;quot; description=&amp;quot;COM_CATEGORIES_ACCESS_DELETE_DESC&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;action name=&amp;quot;core.edit&amp;quot; title=&amp;quot;JACTION_EDIT&amp;quot; description=&amp;quot;COM_CATEGORIES_ACCESS_EDIT_DESC&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;action name=&amp;quot;core.edit.state&amp;quot; title=&amp;quot;JACTION_EDITSTATE&amp;quot; description=&amp;quot;COM_CATEGORIES_ACCESS_EDITSTATE_DESC&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;action name=&amp;quot;core.edit.own&amp;quot; title=&amp;quot;JACTION_EDITOWN&amp;quot; description=&amp;quot;COM_CATEGORIES_ACCESS_EDITOWN_DESC&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/section&amp;gt;&lt;br /&gt;
	&amp;lt;section name=&amp;quot;message&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;action name=&amp;quot;core.delete&amp;quot; title=&amp;quot;JACTION_DELETE&amp;quot; description=&amp;quot;COM_HELLOWORLD_ACCESS_DELETE_DESC&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;action name=&amp;quot;core.edit&amp;quot; title=&amp;quot;JACTION_EDIT&amp;quot; description=&amp;quot;COM_HELLOWORLD_ACCESS_EDIT_DESC&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/section&amp;gt;&lt;br /&gt;
&amp;lt;/access&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Adding the setting of permissions in the component&#039;s Preferences ===&lt;br /&gt;
Since we now use Access Control permissions in our component, we need to be able to set them at the component level. That is done in the Preferences of this component: the screen you see after clicking the &#039;Options&#039; button. The config.xml-file is a form-definition for those Preferences. We could define the component level actions here too, as a child of the &amp;quot;rules&amp;quot; field-tag, but it is now preferred to also put those actions in &amp;lt;tt&amp;gt;access.xml&amp;lt;/tt&amp;gt; in that way all access rules for this component are on one spot.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;admin/config.xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;admin/config.xml&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; highlight=&amp;quot;19-34&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;config&amp;gt;&lt;br /&gt;
	&amp;lt;fieldset&lt;br /&gt;
		name=&amp;quot;greetings&amp;quot;&lt;br /&gt;
		label=&amp;quot;COM_HELLOWORLD_CONFIG_GREETING_SETTINGS_LABEL&amp;quot;&lt;br /&gt;
		description=&amp;quot;COM_HELLOWORLD_CONFIG_GREETING_SETTINGS_DESC&amp;quot;&lt;br /&gt;
	&amp;gt;&lt;br /&gt;
		&amp;lt;field&lt;br /&gt;
			name=&amp;quot;show_category&amp;quot;&lt;br /&gt;
			type=&amp;quot;radio&amp;quot;&lt;br /&gt;
			label=&amp;quot;COM_HELLOWORLD_HELLOWORLD_FIELD_SHOW_CATEGORY_LABEL&amp;quot;&lt;br /&gt;
			description=&amp;quot;COM_HELLOWORLD_HELLOWORLD_FIELD_SHOW_CATEGORY_DESC&amp;quot;&lt;br /&gt;
			default=&amp;quot;0&amp;quot;&lt;br /&gt;
		&amp;gt;&lt;br /&gt;
			&amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;JHIDE&amp;lt;/option&amp;gt;&lt;br /&gt;
			&amp;lt;option value=&amp;quot;1&amp;quot;&amp;gt;JSHOW&amp;lt;/option&amp;gt;&lt;br /&gt;
		&amp;lt;/field&amp;gt;&lt;br /&gt;
	&amp;lt;/fieldset&amp;gt;&lt;br /&gt;
	&amp;lt;fieldset&lt;br /&gt;
		name=&amp;quot;permissions&amp;quot;&lt;br /&gt;
		label=&amp;quot;JCONFIG_PERMISSIONS_LABEL&amp;quot;&lt;br /&gt;
		description=&amp;quot;JCONFIG_PERMISSIONS_DESC&amp;quot;&lt;br /&gt;
	&amp;gt;&lt;br /&gt;
		&amp;lt;field&lt;br /&gt;
			name=&amp;quot;rules&amp;quot;&lt;br /&gt;
			type=&amp;quot;rules&amp;quot;&lt;br /&gt;
			label=&amp;quot;JCONFIG_PERMISSIONS_LABEL&amp;quot;&lt;br /&gt;
			class=&amp;quot;inputbox&amp;quot;&lt;br /&gt;
			validate=&amp;quot;rules&amp;quot;&lt;br /&gt;
			filter=&amp;quot;rules&amp;quot;&lt;br /&gt;
			component=&amp;quot;com_helloworld&amp;quot;&lt;br /&gt;
			section=&amp;quot;component&amp;quot;&lt;br /&gt;
		/&amp;gt;&lt;br /&gt;
	&amp;lt;/fieldset&amp;gt;&lt;br /&gt;
&amp;lt;/config&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Displaying only the right toolbar buttons ===&lt;br /&gt;
&lt;br /&gt;
Which toolbar buttons to display depends on the Access Control permissions for the user. We put all permissions for this user in the $canDo property of the view; so we can eventually refer to it in layouts (in the edit-form for example).&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;tt&amp;gt;admin/views/helloworlds/view.html.php&amp;lt;/tt&amp;gt;, put this code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;admin/views/helloworlds/view.html.php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;admin/views/helloworlds/view.html.php&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;42-44,83-85,87-89,91-93,95-98,100&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
/**&lt;br /&gt;
 * @package     Joomla.Administrator&lt;br /&gt;
 * @subpackage  com_helloworld&lt;br /&gt;
 *&lt;br /&gt;
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.&lt;br /&gt;
 * @license     GNU General Public License version 2 or later; see LICENSE.txt&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
// No direct access to this file&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die(&#039;Restricted access&#039;);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * HelloWorlds View&lt;br /&gt;
 *&lt;br /&gt;
 * @since  0.0.1&lt;br /&gt;
 */&lt;br /&gt;
class HelloWorldViewHelloWorlds extends JViewLegacy&lt;br /&gt;
{&lt;br /&gt;
	/**&lt;br /&gt;
	 * Display the Hello World view&lt;br /&gt;
	 *&lt;br /&gt;
	 * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.&lt;br /&gt;
	 *&lt;br /&gt;
	 * @return  void&lt;br /&gt;
	 */&lt;br /&gt;
	function display($tpl = null)&lt;br /&gt;
	{&lt;br /&gt;
		&lt;br /&gt;
		// Get application&lt;br /&gt;
		$app = JFactory::getApplication();&lt;br /&gt;
		$context = &amp;quot;helloworld.list.admin.helloworld&amp;quot;;&lt;br /&gt;
		// Get data from the model&lt;br /&gt;
		$this-&amp;gt;items		= $this-&amp;gt;get(&#039;Items&#039;);&lt;br /&gt;
		$this-&amp;gt;pagination	= $this-&amp;gt;get(&#039;Pagination&#039;);&lt;br /&gt;
		$this-&amp;gt;state		= $this-&amp;gt;get(&#039;State&#039;);&lt;br /&gt;
		$this-&amp;gt;filter_order	= $app-&amp;gt;getUserStateFromRequest($context.&#039;filter_order&#039;, &#039;filter_order&#039;, &#039;greeting&#039;, &#039;cmd&#039;);&lt;br /&gt;
		$this-&amp;gt;filter_order_Dir = $app-&amp;gt;getUserStateFromRequest($context.&#039;filter_order_Dir&#039;, &#039;filter_order_Dir&#039;, &#039;asc&#039;, &#039;cmd&#039;);&lt;br /&gt;
		$this-&amp;gt;filterForm    	= $this-&amp;gt;get(&#039;FilterForm&#039;);&lt;br /&gt;
		$this-&amp;gt;activeFilters 	= $this-&amp;gt;get(&#039;ActiveFilters&#039;);&lt;br /&gt;
&lt;br /&gt;
		// What Access Permissions does this user have? What can (s)he do?&lt;br /&gt;
		$this-&amp;gt;canDo = JHelperContent::getActions();&lt;br /&gt;
&lt;br /&gt;
		// Check for errors.&lt;br /&gt;
		if (count($errors = $this-&amp;gt;get(&#039;Errors&#039;)))&lt;br /&gt;
		{&lt;br /&gt;
			throw new Exception(implode(&amp;quot;\n&amp;quot;, $errors), 500);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Set the submenu&lt;br /&gt;
		HelloWorldHelper::addSubmenu(&#039;helloworlds&#039;);&lt;br /&gt;
&lt;br /&gt;
		// Set the toolbar and number of found items&lt;br /&gt;
		$this-&amp;gt;addToolBar();&lt;br /&gt;
&lt;br /&gt;
		// Display the template&lt;br /&gt;
		parent::display($tpl);&lt;br /&gt;
&lt;br /&gt;
		// Set the document&lt;br /&gt;
		$this-&amp;gt;setDocument();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add the page title and toolbar.&lt;br /&gt;
	 *&lt;br /&gt;
	 * @return  void&lt;br /&gt;
	 *&lt;br /&gt;
	 * @since   1.6&lt;br /&gt;
	 */&lt;br /&gt;
	protected function addToolBar()&lt;br /&gt;
	{&lt;br /&gt;
		$title = JText::_(&#039;COM_HELLOWORLD_MANAGER_HELLOWORLDS&#039;);&lt;br /&gt;
&lt;br /&gt;
		if ($this-&amp;gt;pagination-&amp;gt;total)&lt;br /&gt;
		{&lt;br /&gt;
			$title .= &amp;quot;&amp;lt;span style=&#039;font-size: 0.5em; vertical-align: middle;&#039;&amp;gt;(&amp;quot; . $this-&amp;gt;pagination-&amp;gt;total . &amp;quot;)&amp;lt;/span&amp;gt;&amp;quot;;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		JToolBarHelper::title($title, &#039;helloworld&#039;);&lt;br /&gt;
&lt;br /&gt;
		if ($this-&amp;gt;canDo-&amp;gt;get(&#039;core.create&#039;)) &lt;br /&gt;
		{&lt;br /&gt;
			JToolBarHelper::addNew(&#039;helloworld.add&#039;, &#039;JTOOLBAR_NEW&#039;);&lt;br /&gt;
		}&lt;br /&gt;
		if ($this-&amp;gt;canDo-&amp;gt;get(&#039;core.edit&#039;)) &lt;br /&gt;
		{&lt;br /&gt;
			JToolBarHelper::editList(&#039;helloworld.edit&#039;, &#039;JTOOLBAR_EDIT&#039;);&lt;br /&gt;
		}&lt;br /&gt;
		if ($this-&amp;gt;canDo-&amp;gt;get(&#039;core.delete&#039;)) &lt;br /&gt;
		{&lt;br /&gt;
			JToolBarHelper::deleteList(&#039;&#039;, &#039;helloworlds.delete&#039;, &#039;JTOOLBAR_DELETE&#039;);&lt;br /&gt;
		}&lt;br /&gt;
		if ($this-&amp;gt;canDo-&amp;gt;get(&#039;core.admin&#039;)) &lt;br /&gt;
		{&lt;br /&gt;
			JToolBarHelper::divider();&lt;br /&gt;
			JToolBarHelper::preferences(&#039;com_helloworld&#039;);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	/**&lt;br /&gt;
	 * Method to set up the document properties&lt;br /&gt;
	 *&lt;br /&gt;
	 * @return void&lt;br /&gt;
	 */&lt;br /&gt;
	protected function setDocument() &lt;br /&gt;
	{&lt;br /&gt;
		$document = JFactory::getDocument();&lt;br /&gt;
		$document-&amp;gt;setTitle(JText::_(&#039;COM_HELLOWORLD_ADMINISTRATION&#039;));&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the &#039;&#039;admin/views/helloworld/view.html.php&#039;&#039;, put this code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;admin/views/helloworld/view.html.php&amp;quot;&amp;gt;&lt;br /&gt;
&#039;&#039;admin/views/helloworld/view.html.php&#039;&#039;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;23,39-41,76-78,81-89,93-112&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
/**&lt;br /&gt;
 * @package     Joomla.Administrator&lt;br /&gt;
 * @subpackage  com_helloworld&lt;br /&gt;
 *&lt;br /&gt;
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.&lt;br /&gt;
 * @license     GNU General Public License version 2 or later; see LICENSE.txt&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
// No direct access to this file&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die(&#039;Restricted access&#039;);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * HelloWorld View&lt;br /&gt;
 *&lt;br /&gt;
 * @since  0.0.1&lt;br /&gt;
 */&lt;br /&gt;
class HelloWorldViewHelloWorld extends JViewLegacy&lt;br /&gt;
{&lt;br /&gt;
	protected $form;&lt;br /&gt;
	protected $item;&lt;br /&gt;
	protected $script;&lt;br /&gt;
	protected $canDo;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Display the Hello World view&lt;br /&gt;
	 *&lt;br /&gt;
	 * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.&lt;br /&gt;
	 *&lt;br /&gt;
	 * @return  void&lt;br /&gt;
	 */&lt;br /&gt;
	public function display($tpl = null)&lt;br /&gt;
	{&lt;br /&gt;
		// Get the Data&lt;br /&gt;
		$this-&amp;gt;form = $this-&amp;gt;get(&#039;Form&#039;);&lt;br /&gt;
		$this-&amp;gt;item = $this-&amp;gt;get(&#039;Item&#039;);&lt;br /&gt;
		$this-&amp;gt;script = $this-&amp;gt;get(&#039;Script&#039;);&lt;br /&gt;
&lt;br /&gt;
		// What Access Permissions does this user have? What can (s)he do?&lt;br /&gt;
		$this-&amp;gt;canDo = JHelperContent::getActions($this-&amp;gt;item-&amp;gt;id);&lt;br /&gt;
&lt;br /&gt;
		// Check for errors.&lt;br /&gt;
		if (count($errors = $this-&amp;gt;get(&#039;Errors&#039;)))&lt;br /&gt;
		{&lt;br /&gt;
			throw new Exception(implode(&amp;quot;\n&amp;quot;, $errors), 500);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Set the toolbar&lt;br /&gt;
		$this-&amp;gt;addToolBar();&lt;br /&gt;
&lt;br /&gt;
		// Display the template&lt;br /&gt;
		parent::display($tpl);&lt;br /&gt;
&lt;br /&gt;
		// Set the document&lt;br /&gt;
		$this-&amp;gt;setDocument();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add the page title and toolbar.&lt;br /&gt;
	 *&lt;br /&gt;
	 * @return  void&lt;br /&gt;
	 *&lt;br /&gt;
	 * @since   1.6&lt;br /&gt;
	 */&lt;br /&gt;
	protected function addToolBar()&lt;br /&gt;
	{&lt;br /&gt;
		$input = JFactory::getApplication()-&amp;gt;input;&lt;br /&gt;
&lt;br /&gt;
		// Hide Joomla Administrator Main menu&lt;br /&gt;
		$input-&amp;gt;set(&#039;hidemainmenu&#039;, true);&lt;br /&gt;
&lt;br /&gt;
		$isNew = ($this-&amp;gt;item-&amp;gt;id == 0);&lt;br /&gt;
&lt;br /&gt;
		JToolBarHelper::title($isNew ? JText::_(&#039;COM_HELLOWORLD_MANAGER_HELLOWORLD_NEW&#039;)&lt;br /&gt;
		                             : JText::_(&#039;COM_HELLOWORLD_MANAGER_HELLOWORLD_EDIT&#039;), &#039;helloworld&#039;);&lt;br /&gt;
		// Build the actions for new and existing records.&lt;br /&gt;
		if ($isNew)&lt;br /&gt;
		{&lt;br /&gt;
			// For new records, check the create permission.&lt;br /&gt;
			if ($this-&amp;gt;canDo-&amp;gt;get(&#039;core.create&#039;)) &lt;br /&gt;
			{&lt;br /&gt;
				JToolBarHelper::apply(&#039;helloworld.apply&#039;, &#039;JTOOLBAR_APPLY&#039;);&lt;br /&gt;
				JToolBarHelper::save(&#039;helloworld.save&#039;, &#039;JTOOLBAR_SAVE&#039;);&lt;br /&gt;
				JToolBarHelper::custom(&#039;helloworld.save2new&#039;, &#039;save-new.png&#039;, &#039;save-new_f2.png&#039;,&lt;br /&gt;
				                       &#039;JTOOLBAR_SAVE_AND_NEW&#039;, false);&lt;br /&gt;
			}&lt;br /&gt;
			JToolBarHelper::cancel(&#039;helloworld.cancel&#039;, &#039;JTOOLBAR_CANCEL&#039;);&lt;br /&gt;
		}&lt;br /&gt;
		else&lt;br /&gt;
		{&lt;br /&gt;
			if ($this-&amp;gt;canDo-&amp;gt;get(&#039;core.edit&#039;))&lt;br /&gt;
			{&lt;br /&gt;
				// We can save the new record&lt;br /&gt;
				JToolBarHelper::apply(&#039;helloworld.apply&#039;, &#039;JTOOLBAR_APPLY&#039;);&lt;br /&gt;
				JToolBarHelper::save(&#039;helloworld.save&#039;, &#039;JTOOLBAR_SAVE&#039;);&lt;br /&gt;
 &lt;br /&gt;
				// We can save this record, but check the create permission to see&lt;br /&gt;
				// if we can return to make a new one.&lt;br /&gt;
				if ($this-&amp;gt;canDo-&amp;gt;get(&#039;core.create&#039;)) &lt;br /&gt;
				{&lt;br /&gt;
					JToolBarHelper::custom(&#039;helloworld.save2new&#039;, &#039;save-new.png&#039;, &#039;save-new_f2.png&#039;,&lt;br /&gt;
					                       &#039;JTOOLBAR_SAVE_AND_NEW&#039;, false);&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
			if ($this-&amp;gt;canDo-&amp;gt;get(&#039;core.create&#039;)) &lt;br /&gt;
			{&lt;br /&gt;
				JToolBarHelper::custom(&#039;helloworld.save2copy&#039;, &#039;save-copy.png&#039;, &#039;save-copy_f2.png&#039;,&lt;br /&gt;
				                       &#039;JTOOLBAR_SAVE_AS_COPY&#039;, false);&lt;br /&gt;
			}&lt;br /&gt;
			JToolBarHelper::cancel(&#039;helloworld.cancel&#039;, &#039;JTOOLBAR_CLOSE&#039;);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	/**&lt;br /&gt;
	 * Method to set up the document properties&lt;br /&gt;
	 *&lt;br /&gt;
	 * @return void&lt;br /&gt;
	 */&lt;br /&gt;
	protected function setDocument() &lt;br /&gt;
	{&lt;br /&gt;
		$isNew = ($this-&amp;gt;item-&amp;gt;id == 0);&lt;br /&gt;
		$document = JFactory::getDocument();&lt;br /&gt;
		$document-&amp;gt;setTitle($isNew ? JText::_(&#039;COM_HELLOWORLD_HELLOWORLD_CREATING&#039;)&lt;br /&gt;
		                           : JText::_(&#039;COM_HELLOWORLD_HELLOWORLD_EDITING&#039;));&lt;br /&gt;
		$document-&amp;gt;addScript(JURI::root() . $this-&amp;gt;script);&lt;br /&gt;
		$document-&amp;gt;addScript(JURI::root() . &amp;quot;/administrator/components/com_helloworld&amp;quot;&lt;br /&gt;
		                                  . &amp;quot;/views/helloworld/submitbutton.js&amp;quot;);&lt;br /&gt;
		JText::script(&#039;COM_HELLOWORLD_HELLOWORLD_ERROR_UNACCEPTABLE&#039;);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These two files use the &#039;&#039;getActions&#039;&#039; method defined in the &amp;lt;tt&amp;gt;admin/helpers/helloworld.php&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
In the helper-file, put this code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;admin/helpers/helloworld.php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;admin/helpers/helloworld.php&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;50-72&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
/**&lt;br /&gt;
 * @package     Joomla.Administrator&lt;br /&gt;
 * @subpackage  com_helloworld&lt;br /&gt;
 *&lt;br /&gt;
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.&lt;br /&gt;
 * @license     GNU General Public License version 2 or later; see LICENSE.txt&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
// No direct access to this file&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die(&#039;Restricted access&#039;);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * HelloWorld component helper.&lt;br /&gt;
 *&lt;br /&gt;
 * @param   string  $submenu  The name of the active view.&lt;br /&gt;
 *&lt;br /&gt;
 * @return  void&lt;br /&gt;
 *&lt;br /&gt;
 * @since   1.6&lt;br /&gt;
 */&lt;br /&gt;
abstract class HelloWorldHelper&lt;br /&gt;
{&lt;br /&gt;
	/**&lt;br /&gt;
	 * Configure the Linkbar.&lt;br /&gt;
	 */&lt;br /&gt;
	public static function addSubmenu($submenu) &lt;br /&gt;
	{&lt;br /&gt;
		JSubMenuHelper::addEntry(&lt;br /&gt;
			JText::_(&#039;COM_HELLOWORLD_SUBMENU_MESSAGES&#039;),&lt;br /&gt;
			&#039;index.php?option=com_helloworld&#039;,&lt;br /&gt;
			$submenu == &#039;messages&#039;&lt;br /&gt;
		);&lt;br /&gt;
&lt;br /&gt;
		JSubMenuHelper::addEntry(&lt;br /&gt;
			JText::_(&#039;COM_HELLOWORLD_SUBMENU_CATEGORIES&#039;),&lt;br /&gt;
			&#039;index.php?option=com_categories&amp;amp;view=categories&amp;amp;extension=com_helloworld&#039;,&lt;br /&gt;
			$submenu == &#039;categories&#039;&lt;br /&gt;
		);&lt;br /&gt;
&lt;br /&gt;
		// set some global property&lt;br /&gt;
		$document = JFactory::getDocument();&lt;br /&gt;
		$document-&amp;gt;addStyleDeclaration(&#039;.icon-48-helloworld &#039; .&lt;br /&gt;
		                               &#039;{background-image: url(../media/com_helloworld/images/tux-48x48.png);}&#039;);&lt;br /&gt;
		if ($submenu == &#039;categories&#039;) &lt;br /&gt;
		{&lt;br /&gt;
			$document-&amp;gt;setTitle(JText::_(&#039;COM_HELLOWORLD_ADMINISTRATION_CATEGORIES&#039;));&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Get the actions&lt;br /&gt;
	 */&lt;br /&gt;
	public static function getActions($messageId = 0)&lt;br /&gt;
	{	&lt;br /&gt;
		$result	= new JObject;&lt;br /&gt;
&lt;br /&gt;
		if (empty($messageId)) {&lt;br /&gt;
			$assetName = &#039;com_helloworld&#039;;&lt;br /&gt;
		}&lt;br /&gt;
		else {&lt;br /&gt;
			$assetName = &#039;com_helloworld.message.&#039;.(int) $messageId;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		$actions = JAccess::getActions(&#039;com_helloworld&#039;, &#039;component&#039;);&lt;br /&gt;
&lt;br /&gt;
		foreach ($actions as $action) {&lt;br /&gt;
			$result-&amp;gt;set($action-&amp;gt;name, JFactory::getUser()-&amp;gt;authorise($action-&amp;gt;name, $assetName));&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		return $result;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restricting access to the component ===&lt;br /&gt;
&lt;br /&gt;
The main idea in ACL is to restrict actions to groups of users. The first action to be restricted is access to the administrative backend of the component itself. With your favourite file editor, edit the &amp;lt;tt&amp;gt;admin/helloworld.php&amp;lt;/tt&amp;gt; file and add the lines with the access check.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;admin/helloworld.php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;admin/helloworld.php&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;17-22&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
/**&lt;br /&gt;
 * @package     Joomla.Administrator&lt;br /&gt;
 * @subpackage  com_helloworld&lt;br /&gt;
 *&lt;br /&gt;
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.&lt;br /&gt;
 * @license     GNU General Public License version 2 or later; see LICENSE.txt&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
// No direct access to this file&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die(&#039;Restricted access&#039;);&lt;br /&gt;
&lt;br /&gt;
// Set some global property&lt;br /&gt;
$document = JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addStyleDeclaration(&#039;.icon-helloworld {background-image: url(../media/com_helloworld/images/tux-16x16.png);}&#039;);&lt;br /&gt;
&lt;br /&gt;
// Access check: is this user allowed to access the backend of this component?&lt;br /&gt;
if (!JFactory::getUser()-&amp;gt;authorise(&#039;core.manage&#039;, &#039;com_helloworld&#039;))&lt;br /&gt;
{&lt;br /&gt;
	throw new Exception(JText::_(&#039;JERROR_ALERTNOAUTHOR&#039;));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Require helper file&lt;br /&gt;
JLoader::register(&#039;HelloWorldHelper&#039;, JPATH_COMPONENT . &#039;/helpers/helloworld.php&#039;);&lt;br /&gt;
&lt;br /&gt;
// Get an instance of the controller prefixed by HelloWorld&lt;br /&gt;
$controller = JControllerLegacy::getInstance(&#039;HelloWorld&#039;);&lt;br /&gt;
&lt;br /&gt;
// Perform the Request task&lt;br /&gt;
$controller-&amp;gt;execute(JFactory::getApplication()-&amp;gt;input-&amp;gt;get(&#039;task&#039;));;&lt;br /&gt;
&lt;br /&gt;
// Redirect if set by the controller&lt;br /&gt;
$controller-&amp;gt;redirect();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add the asset_id column to the database table ===&lt;br /&gt;
&lt;br /&gt;
In order to be able to work with JTable an asset_id column has to be added to the database #__helloworld table.&lt;br /&gt;
&lt;br /&gt;
So, &amp;lt;tt&amp;gt;admin/sql/install.mysql.utf8.sql&amp;lt;/tt&amp;gt; becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;admin/sql/install.mysql.utf8.sql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;admin/sql/install.mysql.utf8.sql&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot; highlight=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
DROP TABLE IF EXISTS `#__helloworld`;&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE `#__helloworld` (&lt;br /&gt;
	`id`       INT(11)     NOT NULL AUTO_INCREMENT,&lt;br /&gt;
	`asset_id` INT(10)     NOT NULL DEFAULT &#039;0&#039;,&lt;br /&gt;
	`greeting` VARCHAR(25) NOT NULL,&lt;br /&gt;
	`published` tinyint(4) NOT NULL,&lt;br /&gt;
	`catid`	    int(11)    NOT NULL DEFAULT &#039;0&#039;,&lt;br /&gt;
	`params`   VARCHAR(1024) NOT NULL DEFAULT &#039;&#039;,&lt;br /&gt;
	PRIMARY KEY (`id`)&lt;br /&gt;
)&lt;br /&gt;
	ENGINE =MyISAM&lt;br /&gt;
	AUTO_INCREMENT =0&lt;br /&gt;
	DEFAULT CHARSET =utf8;&lt;br /&gt;
&lt;br /&gt;
INSERT INTO `#__helloworld` (`greeting`) VALUES&lt;br /&gt;
(&#039;Hello World!&#039;),&lt;br /&gt;
(&#039;Good bye World!&#039;);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For updates we add a sql-update-file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;admin/sql/updates/mysql/0.0.14.sql&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;admin/sql/updates/mysql/0.0.14.sql&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
ALTER TABLE`#__helloworld` ADD COLUMN `asset_id` INT(10) UNSIGNED NOT NULL DEFAULT &#039;0&#039; AFTER `id`;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restricting access to the messages ===&lt;br /&gt;
&lt;br /&gt;
So far we have restricted access to the component itself, but we also need to do that at &#039;&#039;message&#039;&#039; level.&lt;br /&gt;
&lt;br /&gt;
To check the &#039;&#039;&#039;&amp;quot;core.delete&amp;quot;&#039;&#039;&#039; permission you need to modify the model class: &amp;lt;tt&amp;gt;admin/models/helloworld.php&amp;lt;/tt&amp;gt; by adding these lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;admin/models/helloworld.php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;admin/models/helloworld.php&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&#039;php&#039; highlight=&amp;quot;96-105&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
/**&lt;br /&gt;
 * @package     Joomla.Administrator&lt;br /&gt;
 * @subpackage  com_helloworld&lt;br /&gt;
 *&lt;br /&gt;
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.&lt;br /&gt;
 * @license     GNU General Public License version 2 or later; see LICENSE.txt&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
// No direct access to this file&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die(&#039;Restricted access&#039;);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * HelloWorld Model&lt;br /&gt;
 *&lt;br /&gt;
 * @since  0.0.1&lt;br /&gt;
 */&lt;br /&gt;
class HelloWorldModelHelloWorld extends JModelAdmin&lt;br /&gt;
{&lt;br /&gt;
	/**&lt;br /&gt;
	 * Method to get a table object, load it if necessary.&lt;br /&gt;
	 *&lt;br /&gt;
	 * @param   string  $type    The table name. Optional.&lt;br /&gt;
	 * @param   string  $prefix  The class prefix. Optional.&lt;br /&gt;
	 * @param   array   $config  Configuration array for model. Optional.&lt;br /&gt;
	 *&lt;br /&gt;
	 * @return  JTable  A JTable object&lt;br /&gt;
	 *&lt;br /&gt;
	 * @since   1.6&lt;br /&gt;
	 */&lt;br /&gt;
	public function getTable($type = &#039;HelloWorld&#039;, $prefix = &#039;HelloWorldTable&#039;, $config = array())&lt;br /&gt;
	{&lt;br /&gt;
		return JTable::getInstance($type, $prefix, $config);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Method to get the record form.&lt;br /&gt;
	 *&lt;br /&gt;
	 * @param   array    $data      Data for the form.&lt;br /&gt;
	 * @param   boolean  $loadData  True if the form is to load its own data (default case), false if not.&lt;br /&gt;
	 *&lt;br /&gt;
	 * @return  mixed    A JForm object on success, false on failure&lt;br /&gt;
	 *&lt;br /&gt;
	 * @since   1.6&lt;br /&gt;
	 */&lt;br /&gt;
	public function getForm($data = array(), $loadData = true)&lt;br /&gt;
	{&lt;br /&gt;
		// Get the form.&lt;br /&gt;
		$form = $this-&amp;gt;loadForm(&lt;br /&gt;
			&#039;com_helloworld.helloworld&#039;,&lt;br /&gt;
			&#039;helloworld&#039;,&lt;br /&gt;
			array(&lt;br /&gt;
				&#039;control&#039; =&amp;gt; &#039;jform&#039;,&lt;br /&gt;
				&#039;load_data&#039; =&amp;gt; $loadData&lt;br /&gt;
			)&lt;br /&gt;
		);&lt;br /&gt;
&lt;br /&gt;
		if (empty($form))&lt;br /&gt;
		{&lt;br /&gt;
			return false;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		return $form;&lt;br /&gt;
	}&lt;br /&gt;
	/**&lt;br /&gt;
	 * Method to get the script that have to be included on the form&lt;br /&gt;
	 *&lt;br /&gt;
	 * @return string	Script files&lt;br /&gt;
	 */&lt;br /&gt;
	public function getScript() &lt;br /&gt;
	{&lt;br /&gt;
		return &#039;administrator/components/com_helloworld/models/forms/helloworld.js&#039;;&lt;br /&gt;
	}&lt;br /&gt;
	/**&lt;br /&gt;
	 * Method to get the data that should be injected in the form.&lt;br /&gt;
	 *&lt;br /&gt;
	 * @return  mixed  The data for the form.&lt;br /&gt;
	 *&lt;br /&gt;
	 * @since   1.6&lt;br /&gt;
	 */&lt;br /&gt;
	protected function loadFormData()&lt;br /&gt;
	{&lt;br /&gt;
		// Check the session for previously entered form data.&lt;br /&gt;
		$data = JFactory::getApplication()-&amp;gt;getUserState(&lt;br /&gt;
			&#039;com_helloworld.edit.helloworld.data&#039;,&lt;br /&gt;
			array()&lt;br /&gt;
		);&lt;br /&gt;
&lt;br /&gt;
		if (empty($data))&lt;br /&gt;
		{&lt;br /&gt;
			$data = $this-&amp;gt;getItem();&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		return $data;&lt;br /&gt;
	}&lt;br /&gt;
	/**&lt;br /&gt;
	 * Method to check if it&#039;s OK to delete a message. Overwrites JModelAdmin::canDelete&lt;br /&gt;
	 */&lt;br /&gt;
	protected function canDelete($record)&lt;br /&gt;
	{&lt;br /&gt;
		if( !empty( $record-&amp;gt;id ) )&lt;br /&gt;
		{&lt;br /&gt;
			return JFactory::getUser()-&amp;gt;authorise( &amp;quot;core.delete&amp;quot;, &amp;quot;com_helloworld.message.&amp;quot; . $record-&amp;gt;id );&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check &#039;&#039;&#039;&amp;quot;core.edit&amp;quot;&#039;&#039;&#039; (and &#039;&#039;&#039;core.add&#039;&#039;&#039; if you wish) you need to update the sub-controller (&#039;&#039;not&#039;&#039; the model). I am not sure why this is so, but that&#039;s how other standard Joomla components do it. You need to add the following lines in the file: &amp;lt;tt&amp;gt;admin/controllers/helloworld.php&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;admin/controllers/helloworld.php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;admin/controllers/helloworld.php&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&#039;php&#039;  highlight=&amp;quot;21-49&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
/**&lt;br /&gt;
 * @package     Joomla.Administrator&lt;br /&gt;
 * @subpackage  com_helloworld&lt;br /&gt;
 *&lt;br /&gt;
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.&lt;br /&gt;
 * @license     GNU General Public License version 2 or later; see LICENSE.txt&lt;br /&gt;
 */&lt;br /&gt;
// No direct access to this file&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die(&#039;Restricted access&#039;);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * HelloWorld Controller&lt;br /&gt;
 *&lt;br /&gt;
 * @package     Joomla.Administrator&lt;br /&gt;
 * @subpackage  com_helloworld&lt;br /&gt;
 * @since       0.0.9&lt;br /&gt;
 */&lt;br /&gt;
class HelloWorldControllerHelloWorld extends JControllerForm&lt;br /&gt;
{&lt;br /&gt;
	/**&lt;br /&gt;
	* Implement to allowAdd or not&lt;br /&gt;
	*&lt;br /&gt;
	* Not used at this time (but you can look at how other components use it....)&lt;br /&gt;
	* Overwrites: JControllerForm::allowAdd&lt;br /&gt;
	*&lt;br /&gt;
	* @param array $data&lt;br /&gt;
	* @return bool&lt;br /&gt;
	*/&lt;br /&gt;
	protected function allowAdd($data = array())&lt;br /&gt;
	{&lt;br /&gt;
		return parent::allowAdd($data);&lt;br /&gt;
	}&lt;br /&gt;
	/**&lt;br /&gt;
	* Implement to allow edit or not&lt;br /&gt;
	* Overwrites: JControllerForm::allowEdit&lt;br /&gt;
	*&lt;br /&gt;
	* @param array $data&lt;br /&gt;
	* @param string $key&lt;br /&gt;
	* @return bool&lt;br /&gt;
	*/&lt;br /&gt;
	protected function allowEdit($data = array(), $key = &#039;id&#039;)&lt;br /&gt;
	{&lt;br /&gt;
		$id = isset( $data[ $key ] ) ? $data[ $key ] : 0;&lt;br /&gt;
		if( !empty( $id ) )&lt;br /&gt;
		{&lt;br /&gt;
			return JFactory::getUser()-&amp;gt;authorise( &amp;quot;core.edit&amp;quot;, &amp;quot;com_helloworld.message.&amp;quot; . $id );&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please note that &#039;&#039;allowAdd&#039;&#039; simply calls its parent. I&#039;ve put it here in case you want to actually use it in your component. If you look at your &amp;lt;tt&amp;gt;admin/access.xml&amp;lt;/tt&amp;gt; file, you will notice there is no &#039;&#039;core.add&#039;&#039; action defined for &amp;quot;messages&amp;quot;, so you will need to add it there as well if you want to be able to configure it in the interface.&lt;br /&gt;
&lt;br /&gt;
=== Setting the permission values in the assets table ===&lt;br /&gt;
&lt;br /&gt;
In order to store permissions for each message in the assets database table, we have to instruct the table class associated with the model to save those permissions in the assets table.&lt;br /&gt;
&lt;br /&gt;
JTable not only provides an interface for storing the data of the record itself in the item&#039;s database table, but also for storing the permissions for that record in the assets database table. Therefore we must add information to the bind()-method about the permission-values. We also have to provide the asset name, asset title and the id of the asset parent via the helloworld JTable. Therefore we override 3 methods:&lt;br /&gt;
* _getAssetName(): a unique name for this asset, by which it can be retrieved&lt;br /&gt;
* _getAssetTitle(): a more human-friendly way to identify the asset (not necessarily unique)&lt;br /&gt;
* _getAssetParentId(): the asset_id of the parent in the asset database table (from whom permissions are inherited)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;admin/tables/helloworld.php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;admin/tables/helloworld.php&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot; highlight=&amp;quot;45-52,80-133&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
/**&lt;br /&gt;
 * @package     Joomla.Administrator&lt;br /&gt;
 * @subpackage  com_helloworld&lt;br /&gt;
 *&lt;br /&gt;
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.&lt;br /&gt;
 * @license     GNU General Public License version 2 or later; see LICENSE.txt&lt;br /&gt;
 */&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;
/**&lt;br /&gt;
 * Hello Table class&lt;br /&gt;
 *&lt;br /&gt;
 * @since  0.0.1&lt;br /&gt;
 */&lt;br /&gt;
class HelloWorldTableHelloWorld extends JTable&lt;br /&gt;
{&lt;br /&gt;
	/**&lt;br /&gt;
	 * Constructor&lt;br /&gt;
	 *&lt;br /&gt;
	 * @param   JDatabaseDriver  &amp;amp;$db  A database connector object&lt;br /&gt;
	 */&lt;br /&gt;
	function __construct(&amp;amp;$db)&lt;br /&gt;
	{&lt;br /&gt;
		parent::__construct(&#039;#__helloworld&#039;, &#039;id&#039;, $db);&lt;br /&gt;
	}&lt;br /&gt;
	/**&lt;br /&gt;
	 * Overloaded bind function&lt;br /&gt;
	 *&lt;br /&gt;
	 * @param       array           named array&lt;br /&gt;
	 * @return      null|string     null is operation was satisfactory, otherwise returns an error&lt;br /&gt;
	 * @see JTable:bind&lt;br /&gt;
	 * @since 1.5&lt;br /&gt;
	 */&lt;br /&gt;
	public function bind($array, $ignore = &#039;&#039;)&lt;br /&gt;
	{&lt;br /&gt;
		if (isset($array[&#039;params&#039;]) &amp;amp;&amp;amp; is_array($array[&#039;params&#039;]))&lt;br /&gt;
		{&lt;br /&gt;
			// Convert the params field to a string.&lt;br /&gt;
			$parameter = new JRegistry;&lt;br /&gt;
			$parameter-&amp;gt;loadArray($array[&#039;params&#039;]);&lt;br /&gt;
			$array[&#039;params&#039;] = (string)$parameter;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Bind the rules.&lt;br /&gt;
		if (isset($array[&#039;rules&#039;]) &amp;amp;&amp;amp; is_array($array[&#039;rules&#039;]))&lt;br /&gt;
		{&lt;br /&gt;
			$rules = new JAccessRules($array[&#039;rules&#039;]);&lt;br /&gt;
			$this-&amp;gt;setRules($rules);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		return parent::bind($array, $ignore);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Overloaded load function&lt;br /&gt;
	 *&lt;br /&gt;
	 * @param       int $pk primary key&lt;br /&gt;
	 * @param       boolean $reset reset data&lt;br /&gt;
	 * @return      boolean&lt;br /&gt;
	 * @see JTable:load&lt;br /&gt;
	 */&lt;br /&gt;
	public function load($pk = null, $reset = true)&lt;br /&gt;
	{&lt;br /&gt;
		if (parent::load($pk, $reset))&lt;br /&gt;
		{&lt;br /&gt;
			// Convert the params field to a registry.&lt;br /&gt;
			$params = new JRegistry;&lt;br /&gt;
			$params-&amp;gt;loadString($this-&amp;gt;params, &#039;JSON&#039;);&lt;br /&gt;
&lt;br /&gt;
			$this-&amp;gt;params = $params;&lt;br /&gt;
			return true;&lt;br /&gt;
		}&lt;br /&gt;
		else&lt;br /&gt;
		{&lt;br /&gt;
			return false;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	/**&lt;br /&gt;
	 * Method to compute the default name of the asset.&lt;br /&gt;
	 * The default name is in the form `table_name.id`&lt;br /&gt;
	 * where id is the value of the primary key of the table.&lt;br /&gt;
	 *&lt;br /&gt;
	 * @return	string&lt;br /&gt;
	 * @since	2.5&lt;br /&gt;
	 */&lt;br /&gt;
	protected function _getAssetName()&lt;br /&gt;
	{&lt;br /&gt;
		$k = $this-&amp;gt;_tbl_key;&lt;br /&gt;
		return &#039;com_helloworld.message.&#039;.(int) $this-&amp;gt;$k;&lt;br /&gt;
	}&lt;br /&gt;
	/**&lt;br /&gt;
	 * Method to return the title to use for the asset table.&lt;br /&gt;
	 *&lt;br /&gt;
	 * @return	string&lt;br /&gt;
	 * @since	2.5&lt;br /&gt;
	 */&lt;br /&gt;
	protected function _getAssetTitle()&lt;br /&gt;
	{&lt;br /&gt;
		return $this-&amp;gt;greeting;&lt;br /&gt;
	}&lt;br /&gt;
	/**&lt;br /&gt;
	 * Method to get the asset-parent-id of the item&lt;br /&gt;
	 *&lt;br /&gt;
	 * @return	int&lt;br /&gt;
	 */&lt;br /&gt;
	protected function _getAssetParentId(JTable $table = NULL, $id = NULL)&lt;br /&gt;
	{&lt;br /&gt;
		// We will retrieve the parent-asset from the Asset-table&lt;br /&gt;
		$assetParent = JTable::getInstance(&#039;Asset&#039;);&lt;br /&gt;
		// Default: if no asset-parent can be found we take the global asset&lt;br /&gt;
		$assetParentId = $assetParent-&amp;gt;getRootId();&lt;br /&gt;
&lt;br /&gt;
		// Find the parent-asset&lt;br /&gt;
		if (($this-&amp;gt;catid) &amp;amp;&amp;amp; !empty($this-&amp;gt;catid))&lt;br /&gt;
		{&lt;br /&gt;
			// The item has a category as asset-parent&lt;br /&gt;
			$assetParent-&amp;gt;loadByName(&#039;com_helloworld.category.&#039; . (int) $this-&amp;gt;catid);&lt;br /&gt;
		}&lt;br /&gt;
		else&lt;br /&gt;
		{&lt;br /&gt;
			// The item has the component as asset-parent&lt;br /&gt;
			$assetParent-&amp;gt;loadByName(&#039;com_helloworld&#039;);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Return the found asset-parent-id&lt;br /&gt;
		if ($assetParent-&amp;gt;id)&lt;br /&gt;
		{&lt;br /&gt;
			$assetParentId=$assetParent-&amp;gt;id;&lt;br /&gt;
		}&lt;br /&gt;
		return $assetParentId;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code for _getAssetParentId() above uses JTableAsset to retrieve the asset_id of the asset-parent. This is different from the code in the current version of com_content, where the asset_id of the category is retrieved from the #__categories database table. That is another possibility; many ways leading to Rome. In com_content however, if an item would not be under a category, then the asset_id of the global asset is returned. That would of course not be right, but is fixed by providing a default category &amp;quot;uncategorised&amp;quot;, so that an article is &#039;&#039;always&#039;&#039; under a category. That is why you cannot just copy the code of _getAssetParentId() in com_content to your own component. The code above is more general.&lt;br /&gt;
&lt;br /&gt;
=== Showing the setting of permissions on the item level ===&lt;br /&gt;
&lt;br /&gt;
Adding the rules field to the form-definition of the edit-form. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;admin/models/forms/helloworld.xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;admin/models/forms/helloworld.xml&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; highlight=&amp;quot;55-74&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;form&lt;br /&gt;
				addrulepath=&amp;quot;/administrator/components/com_helloworld/models/rules&amp;quot;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
	&amp;lt;fieldset&lt;br /&gt;
				name=&amp;quot;details&amp;quot;&lt;br /&gt;
				label=&amp;quot;COM_HELLOWORLD_HELLOWORLD_DETAILS&amp;quot;&lt;br /&gt;
	&amp;gt;&lt;br /&gt;
		&amp;lt;field&lt;br /&gt;
				name=&amp;quot;id&amp;quot;&lt;br /&gt;
				type=&amp;quot;hidden&amp;quot;&lt;br /&gt;
				/&amp;gt;&lt;br /&gt;
		&amp;lt;field&lt;br /&gt;
				name=&amp;quot;greeting&amp;quot;&lt;br /&gt;
				type=&amp;quot;text&amp;quot;&lt;br /&gt;
				label=&amp;quot;COM_HELLOWORLD_HELLOWORLD_GREETING_LABEL&amp;quot;&lt;br /&gt;
				description=&amp;quot;COM_HELLOWORLD_HELLOWORLD_GREETING_DESC&amp;quot;&lt;br /&gt;
				size=&amp;quot;40&amp;quot;&lt;br /&gt;
				class=&amp;quot;inputbox validate-greeting&amp;quot;&lt;br /&gt;
				validate=&amp;quot;greeting&amp;quot;&lt;br /&gt;
				required=&amp;quot;true&amp;quot;&lt;br /&gt;
				default=&amp;quot;&amp;quot;&lt;br /&gt;
				/&amp;gt;&lt;br /&gt;
		&amp;lt;field&lt;br /&gt;
				name=&amp;quot;catid&amp;quot;&lt;br /&gt;
				type=&amp;quot;category&amp;quot;&lt;br /&gt;
				extension=&amp;quot;com_helloworld&amp;quot;&lt;br /&gt;
				class=&amp;quot;inputbox&amp;quot;&lt;br /&gt;
				default=&amp;quot;&amp;quot;&lt;br /&gt;
				label=&amp;quot;COM_HELLOWORLD_HELLOWORLD_FIELD_CATID_LABEL&amp;quot;&lt;br /&gt;
				description=&amp;quot;COM_HELLOWORLD_HELLOWORLD_FIELD_CATID_DESC&amp;quot;&lt;br /&gt;
				required=&amp;quot;true&amp;quot;&lt;br /&gt;
		&amp;gt;&lt;br /&gt;
			&amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;JOPTION_SELECT_CATEGORY&amp;lt;/option&amp;gt;&lt;br /&gt;
		&amp;lt;/field&amp;gt;&lt;br /&gt;
	&amp;lt;/fieldset&amp;gt;&lt;br /&gt;
	&amp;lt;fields name=&amp;quot;params&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;fieldset&lt;br /&gt;
				name=&amp;quot;params&amp;quot;&lt;br /&gt;
				label=&amp;quot;JGLOBAL_FIELDSET_DISPLAY_OPTIONS&amp;quot;&lt;br /&gt;
		&amp;gt;&lt;br /&gt;
			&amp;lt;field&lt;br /&gt;
					name=&amp;quot;show_category&amp;quot;&lt;br /&gt;
					type=&amp;quot;list&amp;quot;&lt;br /&gt;
					label=&amp;quot;COM_HELLOWORLD_HELLOWORLD_FIELD_SHOW_CATEGORY_LABEL&amp;quot;&lt;br /&gt;
					description=&amp;quot;COM_HELLOWORLD_HELLOWORLD_FIELD_SHOW_CATEGORY_DESC&amp;quot;&lt;br /&gt;
					default=&amp;quot;&amp;quot;&lt;br /&gt;
			&amp;gt;&lt;br /&gt;
				&amp;lt;option value=&amp;quot;&amp;quot;&amp;gt;JGLOBAL_USE_GLOBAL&amp;lt;/option&amp;gt;&lt;br /&gt;
				&amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;JHIDE&amp;lt;/option&amp;gt;&lt;br /&gt;
				&amp;lt;option value=&amp;quot;1&amp;quot;&amp;gt;JSHOW&amp;lt;/option&amp;gt;&lt;br /&gt;
			&amp;lt;/field&amp;gt;&lt;br /&gt;
		&amp;lt;/fieldset&amp;gt;&lt;br /&gt;
	&amp;lt;/fields&amp;gt;&lt;br /&gt;
	&amp;lt;fieldset&lt;br /&gt;
			name=&amp;quot;accesscontrol&amp;quot;&lt;br /&gt;
			label=&amp;quot;COM_HELLOWORLD_FIELDSET_RULES&amp;quot;&lt;br /&gt;
	&amp;gt;&lt;br /&gt;
    	&amp;lt;field&lt;br /&gt;
				name=&amp;quot;asset_id&amp;quot;&lt;br /&gt;
				type=&amp;quot;hidden&amp;quot;&lt;br /&gt;
				filter=&amp;quot;unset&amp;quot;&lt;br /&gt;
				/&amp;gt;&lt;br /&gt;
    	&amp;lt;field&lt;br /&gt;
				name=&amp;quot;rules&amp;quot;&lt;br /&gt;
				type=&amp;quot;rules&amp;quot;&lt;br /&gt;
				label=&amp;quot;COM_HELLOWORLD_FIELD_RULES_LABEL&amp;quot;&lt;br /&gt;
				filter=&amp;quot;rules&amp;quot;&lt;br /&gt;
				validate=&amp;quot;rules&amp;quot;&lt;br /&gt;
				class=&amp;quot;inputbox&amp;quot;&lt;br /&gt;
				component=&amp;quot;com_helloworld&amp;quot;&lt;br /&gt;
				section=&amp;quot;message&amp;quot;&lt;br /&gt;
				/&amp;gt;&lt;br /&gt;
    &amp;lt;/fieldset&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now the ACL interface is displayed at the bottom of the Helloworld editform too (the &#039;&#039;edit.php&#039;&#039; file automatically get the fieldsets from the above xml).&lt;br /&gt;
&lt;br /&gt;
=== Adding language strings ===&lt;br /&gt;
We used 4 language strings that have to be added to the backend language-file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;admin/language/en-GB/en-GB.com_helloworld.ini&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;admin/language/en-GB/en-GB.com_helloworld.ini&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot; highlight=&amp;quot;41-44&amp;quot;&amp;gt;&lt;br /&gt;
; Joomla! Project&lt;br /&gt;
; Copyright (C) 2005 - 2015 Open Source Matters. All rights reserved.&lt;br /&gt;
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php&lt;br /&gt;
; Note : All ini files need to be saved as UTF-8&lt;br /&gt;
&lt;br /&gt;
COM_HELLOWORLD_ADMINISTRATION=&amp;quot;HelloWorld - Administration&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_ADMINISTRATION_CATEGORIES=&amp;quot;HelloWorld - Categories&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_NUM=&amp;quot;#&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_HELLOWORLDS_FILTER=&amp;quot;Filters&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_PUBLISHED=&amp;quot;Published&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_HELLOWORLDS_NAME=&amp;quot;Name&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_ID=&amp;quot;Id&amp;quot;&lt;br /&gt;
&lt;br /&gt;
COM_HELLOWORLD_HELLOWORLD_CREATING=&amp;quot;HelloWorld - Creating&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_HELLOWORLD_DETAILS=&amp;quot;Details&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_HELLOWORLD_EDITING=&amp;quot;HelloWorld - Editing&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_HELLOWORLD_ERROR_UNACCEPTABLE=&amp;quot;Some values are unacceptable&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_HELLOWORLD_FIELD_CATID_DESC=&amp;quot;The category the messages belongs to&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_HELLOWORLD_FIELD_CATID_LABEL=&amp;quot;Category&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC=&amp;quot;This message will be displayed&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_LABEL=&amp;quot;Message&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_HELLOWORLD_FIELD_SHOW_CATEGORY_LABEL=&amp;quot;Show category&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_HELLOWORLD_FIELD_SHOW_CATEGORY_DESC=&amp;quot;If set to Show, the title of the message&amp;amp;rsquo;s category will show.&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_HELLOWORLD_HEADING_GREETING=&amp;quot;Greeting&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_HELLOWORLD_HEADING_ID=&amp;quot;Id&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_MANAGER_HELLOWORLD_EDIT=&amp;quot;HelloWorld manager: Edit Message&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_MANAGER_HELLOWORLD_NEW=&amp;quot;HelloWorld manager: New Message&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_MANAGER_HELLOWORLDS=&amp;quot;HelloWorld manager&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_EDIT_HELLOWORLD=&amp;quot;Edit message&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_N_ITEMS_DELETED_1=&amp;quot;One message deleted&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_N_ITEMS_DELETED_MORE=&amp;quot;%d messages deleted&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_N_ITEMS_PUBLISHED=&amp;quot;%d message(s) published&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_N_ITEMS_UNPUBLISHED=&amp;quot;%d message(s) unpublished&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_HELLOWORLD_GREETING_LABEL=&amp;quot;Greeting&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_HELLOWORLD_GREETING_DESC=&amp;quot;Add Hello World Greeting&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_SUBMENU_MESSAGES=&amp;quot;Messages&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_SUBMENU_CATEGORIES=&amp;quot;Categories&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_CONFIGURATION=&amp;quot;HelloWorld Configuration&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_CONFIG_GREETING_SETTINGS_LABEL=&amp;quot;Messages settings&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_CONFIG_GREETING_SETTINGS_DESC=&amp;quot;Settings that will be applied to all messages by default&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_FIELDSET_RULES=&amp;quot;Message Permissions&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_FIELD_RULES_LABEL=&amp;quot;Permissions&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_ACCESS_DELETE_DESC=&amp;quot;Is this group allowed to edit this message?&amp;quot;&lt;br /&gt;
COM_HELLOWORLD_ACCESS_DELETE_DESC=&amp;quot;Is this group allowed to delete this message?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further reading ==&lt;br /&gt;
More information on actions, assets and ACL can be found on the following pages:&lt;br /&gt;
* General information and use: [[S:MyLanguage/Access Control List/1.6-2.5/Tutorial|Access Control List/1.6-2.5/Tutorial]]&lt;br /&gt;
* Technical information, under construction: [[S:MyLanguage/ACL Technique in Joomla!|ACL Technique in Joomla!]]&lt;br /&gt;
* [[S:MyLanguage/How to implement actions in your code|How to implement actions in your code]]&lt;br /&gt;
* [[S:MyLanguage/Adding ACL rules to your component|Adding ACL rules to your component]]&lt;br /&gt;
&lt;br /&gt;
== Deprecated classes ==&lt;br /&gt;
For the moment we leave the &#039;&#039;&#039;deprecated JError&#039;&#039;&#039;-references as they are. They will probably still be available in Joomla! 3.x. We cannot just change them to JLog::add() statements because in Joomla! 2.5 the messages will then not be enqueued (as there is no messagequeue-logger added as is in /libraries/cms.php in Joomla! 3.0). Other solutions, like using $app-&amp;gt;enqueueMessage() or directly throwing PHP-exceptions as showstopper are also possible, but then there would still be numerous references to JError throughout the application. For instance in the view, we now check for errors raised in the model with: &amp;lt;span style=&amp;quot;color:#900&amp;quot;&amp;gt;count($errors = $this-&amp;gt;get(&#039;Errors&#039;))&amp;lt;/span&amp;gt;, which uses JError from the JObject that was the base for JModel. To get the same functionality without using JError at all, we would have to change the way the Model raises those errors and warnings now. If we want to make an application that would work in Joomla! 2.5 and 3.x we can continue using JError. The moment we want to use our 3.x extensions also in 4.x we will have to change this (and probably a lot more too). This tutorial is now primarily focused on Joomla! 3.x., so we notice the upcoming change, but leave it there for the moment.&lt;br /&gt;
&lt;br /&gt;
Since Joomla! 2.5.5 the MVC-base-classes JController, JModel and JView got proxies JControllerLegacy, JModelLegacy and JViewLegacy. It is recommended to use those proxies instead of the original classes for forward compatibility with Joomla! CMS 3.x legacy classes.&lt;br /&gt;
&lt;br /&gt;
== Packaging the component ==&lt;br /&gt;
&lt;br /&gt;
Content of your code directory&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#helloworld.xml|helloworld.xml]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_a_view_to_the_site_part#site/helloworld.php|site/helloworld.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_a_view_to_the_site_part#site/controller.php|site/controller.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/views/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/views/helloworld/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_a_view_to_the_site_part#site/views/helloworld/view.html.php|site/views/helloworld/view.html.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/views/helloworld/tmpl/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Using_the_database#site/views/helloworld/tmpl/default.xml|site/views/helloworld/tmpl/default.xml]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_a_view_to_the_site_part#site/views/helloworld/tmpl/default.php|site/views/helloworld/tmpl/default.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/models/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Using_the_database#site/models/helloworld.php|site/models/helloworld.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/language/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/language/en-GB/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.x:Developing a MVC Component/Adding language management#site.2Flanguage.2Fen-GB.2Fen-GB.com_helloworld.ini|site/language/en-GB/en-GB.com_helloworld.ini]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Basic_backend#admin/helloworld.php|admin/helloworld.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_configuration#admin/config.xml|admin/config.xml]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Basic_backend#admin/controller.php|admin/controller.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_categories#admin/access.xml|admin/access.xml]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_categories#admin/helpers/helloworld.php|admin/helpers/helloworld.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/helpers/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Using_the_database#admin/sql/install.mysql.utf8.sql|admin/sql/install.mysql.utf8.sql]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Using_the_database#admin/sql/uninstall.mysql.utf8.sql|admin/sql/uninstall.mysql.utf8.sql]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/updates/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/updates/mysql/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#admin/sql/updates/mysql/0.0.1.sql|admin/sql/updates/mysql/0.0.1.sql]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Using_the_database#admin/sql/install.mysql.utf8.sql|admin/sql/updates/mysql/0.0.6.sql]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_categories#admin/sql/updates/mysql/0.0.12.sql|admin/sql/updates/mysql/0.0.12.sql]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_configuration#admin/sql/updates/mysql/0.0.13.sql|admin/sql/updates/mysql/0.0.13.sql]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_ACL#admin/sql/updates/mysql/0.0.14.sql|admin/sql/updates/mysql/0.0.14.sql]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/fields/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Using_the_database#admin/models/fields/helloworld.php|admin/models/fields/helloworld.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Basic_backend#admin/models/helloworlds.php|admin/models/helloworlds.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/models/helloworlds.php|admin/models/helloworld.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/forms/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_verifications#admin/models/forms/helloworld.js|admin/models/forms/helloworld.js]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/models/forms/helloworld.xml|admin/models/forms/helloworld.xml]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_verifications#admin/models/rules/greeting.php|admin/models/rules/greeting.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/rules/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/controllers/helloworld.php|admin/controllers/helloworld.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/controllers/helloworlds.php|admin/controllers/helloworlds.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/controllers/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworld/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/views/helloworld/view.html.php|admin/views/helloworld/view.html.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_backend_actions#admin/views/helloworld/tmpl/edit.php|admin/views/helloworld/tmpl/edit.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_verifications#admin/views/helloworld/submitbutton.js|admin/views/helloworld/submitbutton.js]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/view.html.php|admin/views/helloworlds/view.html.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/tmpl/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/tmpl/default.php|admin/views/helloworlds/tmpl/default.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/tables/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Using_the_database#admin/tables/helloworld.php|admin/tables/helloworld.php]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/language/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/language/en-GB/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.x:Developing a MVC Component/Adding language management#admin.2Flanguage.2Fen-GB.2Fen-GB.com_helloworld.ini|admin/language/en-GB/en-GB.com_helloworld.ini]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.x:Developing a MVC Component/Adding language management#admin.2Flanguage.2Fen-GB.2Fen-GB.com_helloworld.sys.ini|admin/language/en-GB/en-GB.com_helloworld.sys.ini]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|media/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|media/images/index.html]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.x:Developing_a_MVC_Component/Adding_decorations_to_the_backend#Adding_some_icons|media/images/tux-16x16.png]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;[[S:MyLanguage/J3.x:Developing_a_MVC_Component/Adding_decorations_to_the_backend#Adding_some_icons|media/images/tux-48x48.png]]&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a compressed file of this directory or directly download the [https://github.com/scionescire/Joomla-3.2-Hello-World-Component/archive/step-14-adding-ACL.zip archive] and install it using the extension manager of Joomla. You can add a menu item of this component using the menu manager in the backend.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;helloworld.xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;helloworld.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;component&amp;quot; version=&amp;quot;3.2.0&amp;quot; method=&amp;quot;upgrade&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&amp;lt;name&amp;gt;COM_HELLOWORLD&amp;lt;/name&amp;gt;&lt;br /&gt;
	&amp;lt;!-- The following elements are optional and free of formatting constraints --&amp;gt;&lt;br /&gt;
	&amp;lt;creationDate&amp;gt;February 2015&amp;lt;/creationDate&amp;gt;&lt;br /&gt;
	&amp;lt;author&amp;gt;John Doe&amp;lt;/author&amp;gt;&lt;br /&gt;
	&amp;lt;authorEmail&amp;gt;john.doe@example.org&amp;lt;/authorEmail&amp;gt;&lt;br /&gt;
	&amp;lt;authorUrl&amp;gt;http://www.example.org&amp;lt;/authorUrl&amp;gt;&lt;br /&gt;
	&amp;lt;copyright&amp;gt;Copyright Info&amp;lt;/copyright&amp;gt;&lt;br /&gt;
	&amp;lt;license&amp;gt;License Info&amp;lt;/license&amp;gt;&lt;br /&gt;
	&amp;lt;!--  The version string is recorded in the components table --&amp;gt;&lt;br /&gt;
	&amp;lt;version&amp;gt;0.0.14&amp;lt;/version&amp;gt;&lt;br /&gt;
	&amp;lt;!-- The description is optional and defaults to the name --&amp;gt;&lt;br /&gt;
	&amp;lt;description&amp;gt;COM_HELLOWORLD_DESCRIPTION&amp;lt;/description&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&amp;lt;install&amp;gt; &amp;lt;!-- Runs on install --&amp;gt;&lt;br /&gt;
		&amp;lt;sql&amp;gt;&lt;br /&gt;
			&amp;lt;file driver=&amp;quot;mysql&amp;quot; charset=&amp;quot;utf8&amp;quot;&amp;gt;sql/install.mysql.utf8.sql&amp;lt;/file&amp;gt;&lt;br /&gt;
		&amp;lt;/sql&amp;gt;&lt;br /&gt;
	&amp;lt;/install&amp;gt;&lt;br /&gt;
	&amp;lt;uninstall&amp;gt; &amp;lt;!-- Runs on uninstall --&amp;gt;&lt;br /&gt;
		&amp;lt;sql&amp;gt;&lt;br /&gt;
			&amp;lt;file driver=&amp;quot;mysql&amp;quot; charset=&amp;quot;utf8&amp;quot;&amp;gt;sql/uninstall.mysql.utf8.sql&amp;lt;/file&amp;gt;&lt;br /&gt;
		&amp;lt;/sql&amp;gt;&lt;br /&gt;
	&amp;lt;/uninstall&amp;gt;&lt;br /&gt;
	&amp;lt;update&amp;gt; &amp;lt;!-- Runs on update; New since J2.5 --&amp;gt;&lt;br /&gt;
		&amp;lt;schemas&amp;gt;&lt;br /&gt;
			&amp;lt;schemapath type=&amp;quot;mysql&amp;quot;&amp;gt;sql/updates/mysql&amp;lt;/schemapath&amp;gt;&lt;br /&gt;
		&amp;lt;/schemas&amp;gt;&lt;br /&gt;
	&amp;lt;/update&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&amp;lt;!-- Site Main File Copy Section --&amp;gt;&lt;br /&gt;
	&amp;lt;!-- Note the folder attribute: This attribute describes the folder&lt;br /&gt;
		to copy FROM in the package to install therefore files copied&lt;br /&gt;
		in this section are copied from /site/ in the package --&amp;gt;&lt;br /&gt;
	&amp;lt;files folder=&amp;quot;site&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;filename&amp;gt;index.html&amp;lt;/filename&amp;gt;&lt;br /&gt;
		&amp;lt;filename&amp;gt;helloworld.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
		&amp;lt;filename&amp;gt;controller.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
		&amp;lt;folder&amp;gt;views&amp;lt;/folder&amp;gt;&lt;br /&gt;
		&amp;lt;folder&amp;gt;models&amp;lt;/folder&amp;gt;&lt;br /&gt;
	&amp;lt;/files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
        &amp;lt;languages folder=&amp;quot;site/language&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;language tag=&amp;quot;en-GB&amp;quot;&amp;gt;en-GB/en-GB.com_helloworld.ini&amp;lt;/language&amp;gt;&lt;br /&gt;
        &amp;lt;/languages&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&amp;lt;media destination=&amp;quot;com_helloworld&amp;quot; folder=&amp;quot;media&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;filename&amp;gt;index.html&amp;lt;/filename&amp;gt;&lt;br /&gt;
		&amp;lt;folder&amp;gt;images&amp;lt;/folder&amp;gt;&lt;br /&gt;
	&amp;lt;/media&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&amp;lt;administration&amp;gt;&lt;br /&gt;
		&amp;lt;!-- Administration Menu Section --&amp;gt;&lt;br /&gt;
		&amp;lt;menu link=&#039;index.php?option=com_helloworld&#039; img=&amp;quot;../media/com_helloworld/images/tux-16x16.png&amp;quot;&amp;gt;COM_HELLOWORLD_MENU&amp;lt;/menu&amp;gt;&lt;br /&gt;
		&amp;lt;!-- Administration Main File Copy Section --&amp;gt;&lt;br /&gt;
		&amp;lt;!-- Note the folder attribute: This attribute describes the folder&lt;br /&gt;
			to copy FROM in the package to install therefore files copied&lt;br /&gt;
			in this section are copied from /admin/ in the package --&amp;gt;&lt;br /&gt;
		&amp;lt;files folder=&amp;quot;admin&amp;quot;&amp;gt;&lt;br /&gt;
			&amp;lt;!-- Admin Main File Copy Section --&amp;gt;&lt;br /&gt;
			&amp;lt;filename&amp;gt;index.html&amp;lt;/filename&amp;gt;&lt;br /&gt;
			&amp;lt;filename&amp;gt;config.xml&amp;lt;/filename&amp;gt;&lt;br /&gt;
			&amp;lt;filename&amp;gt;helloworld.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
			&amp;lt;filename&amp;gt;controller.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
			&amp;lt;filename&amp;gt;access.xml&amp;lt;/filename&amp;gt;&lt;br /&gt;
			&amp;lt;!-- SQL files section --&amp;gt;&lt;br /&gt;
			&amp;lt;folder&amp;gt;sql&amp;lt;/folder&amp;gt;&lt;br /&gt;
			&amp;lt;!-- tables files section --&amp;gt;&lt;br /&gt;
			&amp;lt;folder&amp;gt;tables&amp;lt;/folder&amp;gt;&lt;br /&gt;
			&amp;lt;!-- models files section --&amp;gt;&lt;br /&gt;
			&amp;lt;folder&amp;gt;models&amp;lt;/folder&amp;gt;&lt;br /&gt;
			&amp;lt;!-- views files section --&amp;gt;&lt;br /&gt;
			&amp;lt;folder&amp;gt;views&amp;lt;/folder&amp;gt;&lt;br /&gt;
			&amp;lt;!-- controllers files section --&amp;gt;&lt;br /&gt;
			&amp;lt;folder&amp;gt;controllers&amp;lt;/folder&amp;gt;&lt;br /&gt;
			&amp;lt;!-- helpers files section --&amp;gt;&lt;br /&gt;
			&amp;lt;folder&amp;gt;helpers&amp;lt;/folder&amp;gt;&lt;br /&gt;
		&amp;lt;/files&amp;gt;&lt;br /&gt;
		&amp;lt;languages folder=&amp;quot;admin/language&amp;quot;&amp;gt;&lt;br /&gt;
        		&amp;lt;language tag=&amp;quot;en-GB&amp;quot;&amp;gt;en-GB/en-GB.com_helloworld.ini&amp;lt;/language&amp;gt;&lt;br /&gt;
                        &amp;lt;language tag=&amp;quot;en-GB&amp;quot;&amp;gt;en-GB/en-GB.com_helloworld.sys.ini&amp;lt;/language&amp;gt;&lt;br /&gt;
		&amp;lt;/languages&amp;gt;&lt;br /&gt;
	&amp;lt;/administration&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/extension&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Contributors ==&lt;br /&gt;
*[[User:Dwarkesh0204|Dwarkesh Soni]]&lt;br /&gt;
*[[User:cdemko|Christophe Demko]]&lt;br /&gt;
*[[User:oaksu|Ozgur Aksu]]&lt;br /&gt;
*[[User:florian_denizot|Florian Denizot]]&lt;br /&gt;
*[[User:HermanPeeren|Herman Peeren]]&lt;br /&gt;
* TDZweb (Ståle Rolf Sæbøe), Elin Waring, Neil via https://groups.google.com/forum/#!topic/joomla-dev-general/aCH3GNA91m4&lt;br /&gt;
*[[User:Scionescire|Scionescire]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;row&amp;quot;&amp;gt; &lt;br /&gt;
&amp;lt;div class=&amp;quot;large-6 columns&amp;quot;&amp;gt;{{Basic button|S:MyLanguage/J3.x:Developing_a_MVC_Component/Adding configuration|Prev: Adding configuration|class=expand success}}&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;large-6 columns&amp;quot;&amp;gt;{{Basic button|S:MyLanguage/J3.x:Developing_a_MVC_Component/Adding an install-uninstall-update script file|Next: Adding an install-uninstall-update script file|class=expand}}&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
[[Category:Joomla! 3.x]]&lt;br /&gt;
[[Category:Joomla! 3.0]]&lt;br /&gt;
[[Category:Joomla! 3.1]]&lt;br /&gt;
[[Category:Joomla! 3.2]]&lt;br /&gt;
[[Category:Joomla! 3.3]]&lt;br /&gt;
[[Category:Joomla! 3.4]]&lt;br /&gt;
[[Category:Beginner Development]]&lt;br /&gt;
[[Category:Component Development]]&lt;br /&gt;
[[Category:Tutorials]]&lt;br /&gt;
[[Category:Tutorials in a Series]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mickmackusa</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=J1.5:Add_text_to_an_article_using_template_overrides&amp;diff=635111</id>
		<title>J1.5:Add text to an article using template overrides</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=J1.5:Add_text_to_an_article_using_template_overrides&amp;diff=635111"/>
		<updated>2019-10-19T05:21:41Z</updated>

		<summary type="html">&lt;p&gt;Mickmackusa: Improved formatting. Best practice is === false.  I am concerned that the whole string value of var text should be wrapped in quotes (but currently isn&amp;#039;t).&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{review}}&lt;br /&gt;
Automatically add text to an article in Joomla! If you want to add standard text (&amp;quot;This text has been added automatically by Joomla!&amp;quot;) to the end of each article that is submitted from the front end, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Create a template override for the file &amp;lt;tt&amp;gt;&amp;lt;joomla_root&amp;gt;/components/com_content/views/article/tmpl/form.php&amp;lt;/tt&amp;gt;.&lt;br /&gt;
#* Create a folder called &amp;lt;tt&amp;gt;&amp;lt;joomla_root&amp;gt;/templates/&amp;lt;your template&amp;gt;/html/com_content/article&amp;lt;/tt&amp;gt;.&amp;lt;br&amp;gt;For the &amp;quot;beez&amp;quot; template, this folder is called &amp;lt;tt&amp;gt;&amp;lt;joomla_root&amp;gt;/templates/beez/html/com_content/article&amp;lt;/tt&amp;gt;.&lt;br /&gt;
#* Copy the standard &amp;lt;tt&amp;gt;form.php&amp;lt;/tt&amp;gt; file from the components folder above to the templates folder.&amp;lt;br&amp;gt;Note: If you already have a form.php file in this folder, don&#039;t copy the file. Just edit it as indicated below.&lt;br /&gt;
# Edit the copy of the file you made in the override folder as follows. Find the line &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
   var text = &amp;lt;?php echo $this-&amp;gt;editor-&amp;gt;getContent( &#039;text&#039; ); ?&amp;gt;&amp;lt;/source&amp;gt; This is line 49 in the 1.5.8 version of this file. Change this to the following: &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;  &lt;br /&gt;
   var text = &amp;lt;?php &lt;br /&gt;
	$addToText = &#039;&amp;lt;p&amp;gt;Joomla! automatically added this text.&amp;lt;/p&amp;gt;&#039;; &lt;br /&gt;
	if (strpos($this-&amp;gt;article-&amp;gt;text, $addToText) === false) {&lt;br /&gt;
           $this-&amp;gt;article-&amp;gt;text .= $addToText;&lt;br /&gt;
	}&lt;br /&gt;
   echo $this-&amp;gt;editor-&amp;gt;getContent( &#039;text&#039; ); ?&amp;gt; &amp;lt;/source&amp;gt; This is checking that the text to be added is not already in the article. If it is not, then it is added to the article. &lt;br /&gt;
Don&#039;t forget to change the text in the variable &amp;lt;code&amp;gt;$addToText&amp;lt;/code&amp;gt; to whatever you need.&lt;br /&gt;
&lt;br /&gt;
That&#039;s it. Now, when you edit an article from the front end, this text will automatically be added. Note that this change does not affect editing from the back end. Also, since this is done as a template override, it only affects pages that use the overridden template.&lt;br /&gt;
&lt;br /&gt;
For more information on template overrides, see the tip [[How to override the output from the Joomla! core]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Tips and tricks]]&lt;br /&gt;
[[Category:Tips and tricks 1.5]]&lt;br /&gt;
[[Category:Article Management]]&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Template Development]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Mickmackusa</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=How_to_use_JDate&amp;diff=635076</id>
		<title>How to use JDate</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=How_to_use_JDate&amp;diff=635076"/>
		<updated>2019-10-19T04:59:52Z</updated>

		<summary type="html">&lt;p&gt;Mickmackusa: some rewording in the description&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;
== Introduction == &amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
JDate is a helper class, extended from PHP&#039;s DateTime class, which allows developers to handle date formatting more efficiently. The class allows developers to format dates for readable strings, MySQL interaction, UNIX timestamp calculation, and also provides helper methods for working in different timezones.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Using JDate == &amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Creating a JDate Instance === &amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
All of the date helper methods require an instance of the JDate class. To begin, you must create one. A JDate object may be created in two ways. One is the typical native method of simply creating a new instance:&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;
$date = new JDate(); // Creates a new JDate object equal to the current time.&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:4--&amp;gt;&lt;br /&gt;
You may also create an instance using the static method defined in JDate:&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;
$date = JDate::getInstance(); // Alias of &#039;new JDate();&#039;&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:5--&amp;gt;&lt;br /&gt;
There is no difference between these methods, as JDate::getInstance simply creates a new instance of JDate exactly like the first method shown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
Alternatively, you may also retrieve the current date (as a JDate object) from JApplication, by using:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;$date = JFactory::getDate();&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Arguments === &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
The JDate constructor (and getInstance static method) accepts two optional parameters: a date string to format and a timezone. Not passing a date string will create a JDate object with the current date and time. Not passing a timezone will allow the JDate object to use the default timezone set.&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:9--&amp;gt;&lt;br /&gt;
The first argument, if used, must be a string that can be parsed using php&#039;s native DateTime constructor. E.g:&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;
$currentTime = new JDate(&#039;now&#039;); // Current date and time&lt;br /&gt;
$tomorrowTime = new JDate(&#039;now +1 day&#039;); // Current date and time, + 1 day.&lt;br /&gt;
$Plus1MonthTime = new JDate(&#039;now +1 month&#039;); // Current date and time, + 1 month.&lt;br /&gt;
$Plus1YearTime = new JDate(&#039;now +1 year&#039;); // Current date and time, + 1 year.&lt;br /&gt;
$Plus1YearAnd1MonthTime = new JDate(&#039;now +1 year +1 month&#039;); // Current date and time, + 1 year and 1 month.&lt;br /&gt;
$PlusTimeToTime = new JDate(&#039;now +1 hour +30 minutes +3 seconds&#039;); // Current date and time, + 1 hour, 30 minutes and 3 seconds&lt;br /&gt;
$PlusTimeToTime = new JDate(&#039;now -1 hour +30 minutes +3 seconds&#039;); // Current date and time, + 1 hour, 30 minutes and 3 seconds&lt;br /&gt;
$CombinedTimeToTime = new JDate(&#039;now -1 hour -30 minutes 23 seconds&#039;); // Current date and time, - 1 hour, +30 minutes and +23 seconds&lt;br /&gt;
&lt;br /&gt;
$date = new JDate(&#039;2012-12-1 15:20:00&#039;); // 3:20 PM, December 1st, 2012&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;
=== Examples === &amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Temporary example of date formats=== &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;&lt;br /&gt;
&amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
JFactory::getDate() gets a JDate object and we then do the JDate toFormat function&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;JFactory::getDate()-&amp;gt;toFormat(&#039;%a %d %b %Y - %H:%M&#039;)&amp;lt;/source&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;
In Joomla! CMS 3.3 API the function &amp;quot;toFormat&amp;quot; was changed to &amp;quot;format&amp;quot;, so the example above should be:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;JFactory::getDate()-&amp;gt;format(&#039;%a %d %b %Y - %H:%M&#039;)&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Function: toISO8601(boolean $local = false) : string === &amp;lt;!--T:19--&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;
$date = new JDate(&#039;2016-01-01 02:00:00&#039;); // A.M. time, in GMT timezone&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;
The user&#039;s local timezone can be ignored by passing a false boolean value as the function parameter or by passing no parameter at all.  Passing a boolean value of true will adjust the datetime to the user&#039;s timezone. In the following example, the user&#039;s timezone is set to &amp;quot;America/New_York&amp;quot;.&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;
$timezone = new DateTimeZone( JFactory::getUser()-&amp;gt;getParam(&#039;timezone&#039;) );&lt;br /&gt;
$date-&amp;gt;setTimezone($timezone);&lt;br /&gt;
echo $date-&amp;gt;toISO8601(false); // 2016-01-01 T 02:00:00 +00:00&lt;br /&gt;
echo $date-&amp;gt;toISO8601(true); // 2015-12-31 T 21:00:00-05:00 (local time in New York)&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:13--&amp;gt;&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mickmackusa</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=How_to_use_JDate&amp;diff=635071</id>
		<title>How to use JDate</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=How_to_use_JDate&amp;diff=635071"/>
		<updated>2019-10-19T04:50:21Z</updated>

		<summary type="html">&lt;p&gt;Mickmackusa: improved English&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;
== Introduction == &amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
JDate is a helper class, extended from PHP&#039;s DateTime class, which allows developers to handle date formatting more efficiently. The class allows developers to format dates for readable strings, MySQL interaction, UNIX timestamp calculation, and also provides helper methods for working in different timezones.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Using JDate == &amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Creating a JDate Instance === &amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
All of the date helper methods require an instance of the JDate class. To begin, you must create one. A JDate object may be created in two ways. One is the typical native method of simply creating a new instance:&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;
$date = new JDate(); // Creates a new JDate object equal to the current time.&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:4--&amp;gt;&lt;br /&gt;
You may also create an instance using the static method defined in JDate:&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;
$date = JDate::getInstance(); // Alias of &#039;new JDate();&#039;&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:5--&amp;gt;&lt;br /&gt;
There is no difference between these methods, as JDate::getInstance simply creates a new instance of JDate exactly like the first method shown.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
Alternatively, you may also retrieve the current date (as a JDate object) from JApplication, by using:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;$date = JFactory::getDate();&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Arguments === &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
The JDate constructor (and getInstance static method) accepts two optional parameters: a date string to format and a timezone. Not passing a date string will create a JDate object with the current date and time. Not passing a timezone will allow the JDate object to use the default timezone set.&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:9--&amp;gt;&lt;br /&gt;
The first argument, if used, must be a string that can be parsed using php&#039;s native DateTime constructor. E.g:&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;
$currentTime = new JDate(&#039;now&#039;); // Current date and time&lt;br /&gt;
$tomorrowTime = new JDate(&#039;now +1 day&#039;); // Current date and time, + 1 day.&lt;br /&gt;
$Plus1MonthTime = new JDate(&#039;now +1 month&#039;); // Current date and time, + 1 month.&lt;br /&gt;
$Plus1YearTime = new JDate(&#039;now +1 year&#039;); // Current date and time, + 1 year.&lt;br /&gt;
$Plus1YearAnd1MonthTime = new JDate(&#039;now +1 year +1 month&#039;); // Current date and time, + 1 year and 1 month.&lt;br /&gt;
$PlusTimeToTime = new JDate(&#039;now +1 hour +30 minutes +3 seconds&#039;); // Current date and time, + 1 hour, 30 minutes and 3 seconds&lt;br /&gt;
$PlusTimeToTime = new JDate(&#039;now -1 hour +30 minutes +3 seconds&#039;); // Current date and time, + 1 hour, 30 minutes and 3 seconds&lt;br /&gt;
$CombinedTimeToTime = new JDate(&#039;now -1 hour -30 minutes 23 seconds&#039;); // Current date and time, - 1 hour, +30 minutes and +23 seconds&lt;br /&gt;
&lt;br /&gt;
$date = new JDate(&#039;2012-12-1 15:20:00&#039;); // 3:20 PM, December 1st, 2012&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;
=== Examples === &amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Temporary example of date formats=== &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;&lt;br /&gt;
&amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
JFactory::getDate() gets a JDate object and we then do the JDate toFormat function&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;JFactory::getDate()-&amp;gt;toFormat(&#039;%a %d %b %Y - %H:%M&#039;)&amp;lt;/source&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;
In Joomla! CMS 3.3 API the function &amp;quot;toFormat&amp;quot; was changed to &amp;quot;format&amp;quot;, so the example above should be:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;JFactory::getDate()-&amp;gt;format(&#039;%a %d %b %Y - %H:%M&#039;)&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Function: toISO8601(boolean $local = false) : string === &amp;lt;!--T:19--&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;
$date = new JDate(&#039;2016-01-01 02:00:00&#039;); // A.M. time, in GMT timezone&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;
We set function param before to &amp;quot;false&amp;quot; and after to &amp;quot;true&amp;quot; (user timezone is set to &amp;quot;America/New_York&amp;quot;), we get:&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;
$timezone = new DateTimeZone( JFactory::getUser()-&amp;gt;getParam(&#039;timezone&#039;) );&lt;br /&gt;
$date-&amp;gt;setTimezone($timezone);&lt;br /&gt;
echo $date-&amp;gt;toISO8601(false); // 2016-01-01 T 02:00:00 +00:00&lt;br /&gt;
echo $date-&amp;gt;toISO8601(true); // 2015-12-31 T 21:00:00-05:00 (local time in New York)&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:13--&amp;gt;&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mickmackusa</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Using_the_JFactory_class&amp;diff=635069</id>
		<title>Using the JFactory class</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Using_the_JFactory_class&amp;diff=635069"/>
		<updated>2019-10-19T03:46:14Z</updated>

		<summary type="html">&lt;p&gt;Mickmackusa: /* JFactory::getUser() */ rewording in the description, fixed deadlink&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Top portal heading|color=white-bkgd|icon=magic|icon-color=#5091cd|size=3x|text-color=#333|title=Tutorial&amp;lt;br /&amp;gt;&lt;br /&gt;
Using the JFactory Class}}&lt;br /&gt;
&amp;lt;noinclude&amp;gt;{{Joomla version|version=3.0|time=and after|comment=&amp;lt;series}}&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
{{-}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
JFactory is the Joomla! Platform class, giving you access to the most important (mostly singletons) parts in Joomla. It contains multiple other objects, like the application one or the Joomla! global configuration.&lt;br /&gt;
&lt;br /&gt;
== JFactory::getApplication() ==&lt;br /&gt;
&lt;br /&gt;
Returns the JApplicationCMS, through it you can access for the example do redirects, access the configuration and the input variables, the Menu or enqueue messages which are shown to the user.&lt;br /&gt;
&lt;br /&gt;
*See [[S:MyLanguage/Using the JFactory class/Using the JApplication class|Using the JApplication class]] for more details.&lt;br /&gt;
&lt;br /&gt;
== JFactory::getDocument() ==&lt;br /&gt;
&lt;br /&gt;
Provides access to the current JDocument, with it you can set Meta data, add styles and scripts and more related to the document.&lt;br /&gt;
&lt;br /&gt;
*See [https://docs.joomla.org/J3.x:Adding_JavaScript_and_CSS_to_the_page Adding JavaScript and CSS to the page]&lt;br /&gt;
&lt;br /&gt;
== JFactory::getDbo() ==&lt;br /&gt;
&lt;br /&gt;
Returns a database object. [https://api.joomla.org/cms-3/classes/JDatabaseDriver.html JDatabase methods] are executed by chaining to the database object.&lt;br /&gt;
&lt;br /&gt;
Examples:&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-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;$query = JFactory::getDbo()-&amp;gt;getQuery(true);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*See also [https://docs.joomla.org/Selecting_data_using_JDatabase Selecting data using JDatabase]&lt;br /&gt;
&lt;br /&gt;
== JFactory::getUser() ==&lt;br /&gt;
&lt;br /&gt;
Returns the user object for the currently logged in user (JUser). The object provides access to preloaded values specific to the logged in user as well as methods within the class. If no user is logged in, the user is deemed a &amp;quot;guest&amp;quot; and the id of the user is set to zero.&lt;br /&gt;
&lt;br /&gt;
*See [https://docs.joomla.org/Accessing_the_current_user_object Accessing the current user object]&lt;br /&gt;
&lt;br /&gt;
== JFactory::getDate() ==&lt;br /&gt;
&lt;br /&gt;
Returns a [[S:MyLanguage/Using the JFactory class/How to use JDate|How to use JDate]] instance, you can also add a time and a timezone offset to it. Without parameters it uses the current time.&lt;br /&gt;
&lt;br /&gt;
== JFactory::getMailer() ==&lt;br /&gt;
&lt;br /&gt;
Provides access to the Joomla Mailer (wrapper around PHPMailer) for sending emails with Joomla.&lt;br /&gt;
&lt;br /&gt;
*See also [[Sending email from extensions]]&lt;br /&gt;
&lt;br /&gt;
== JFactory::getConfig() ==&lt;br /&gt;
&lt;br /&gt;
Returns a registry with the Joomla! configuration file (configuration.php), see JConfig for more details. To access single values you can use &amp;lt;tt&amp;gt;JFactory::getApplication()-&amp;gt;get(&#039;configValue&#039;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*See also Getting global configuration parameters&lt;br /&gt;
&lt;br /&gt;
== JFactory::getSession() ==&lt;br /&gt;
&lt;br /&gt;
Returns the current visitors session. (Make sure Joomla! is called as Webapplication)&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
*[https://api.joomla.org/cms-3/classes/JFactory.html API Docs for JFactory]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
[[Category:JFactory]] &lt;br /&gt;
[[Category:Tutorials]][[Category:Framework]]&lt;br /&gt;
[[Category:Module Development]]&lt;br /&gt;
[[Category:Plugin Development]]&lt;br /&gt;
[[Category:Component Development]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mickmackusa</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Using_the_JFactory_class&amp;diff=635066</id>
		<title>Using the JFactory class</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Using_the_JFactory_class&amp;diff=635066"/>
		<updated>2019-10-19T03:31:21Z</updated>

		<summary type="html">&lt;p&gt;Mickmackusa: /* JFactory::getDocument() */ fixed broken link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Top portal heading|color=white-bkgd|icon=magic|icon-color=#5091cd|size=3x|text-color=#333|title=Tutorial&amp;lt;br /&amp;gt;&lt;br /&gt;
Using the JFactory Class}}&lt;br /&gt;
&amp;lt;noinclude&amp;gt;{{Joomla version|version=3.0|time=and after|comment=&amp;lt;series}}&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
{{-}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
JFactory is the Joomla! Platform class, giving you access to the most important (mostly singletons) parts in Joomla. It contains multiple other objects, like the application one or the Joomla! global configuration.&lt;br /&gt;
&lt;br /&gt;
== JFactory::getApplication() ==&lt;br /&gt;
&lt;br /&gt;
Returns the JApplicationCMS, through it you can access for the example do redirects, access the configuration and the input variables, the Menu or enqueue messages which are shown to the user.&lt;br /&gt;
&lt;br /&gt;
*See [[S:MyLanguage/Using the JFactory class/Using the JApplication class|Using the JApplication class]] for more details.&lt;br /&gt;
&lt;br /&gt;
== JFactory::getDocument() ==&lt;br /&gt;
&lt;br /&gt;
Provides access to the current JDocument, with it you can set Meta data, add styles and scripts and more related to the document.&lt;br /&gt;
&lt;br /&gt;
*See [https://docs.joomla.org/J3.x:Adding_JavaScript_and_CSS_to_the_page Adding JavaScript and CSS to the page]&lt;br /&gt;
&lt;br /&gt;
== JFactory::getDbo() ==&lt;br /&gt;
&lt;br /&gt;
Returns a database object. [https://api.joomla.org/cms-3/classes/JDatabaseDriver.html JDatabase methods] are executed by chaining to the database object.&lt;br /&gt;
&lt;br /&gt;
Examples:&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-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;$query = JFactory::getDbo()-&amp;gt;getQuery(true);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*See also [https://docs.joomla.org/Selecting_data_using_JDatabase Selecting data using JDatabase]&lt;br /&gt;
&lt;br /&gt;
== JFactory::getUser() ==&lt;br /&gt;
&lt;br /&gt;
Returns the current Joomla! user object (JUser), with it you can access information and methods related to users. It is also created for guests, where the id is zero.&lt;br /&gt;
&lt;br /&gt;
*See [[S:MyLanguage/Using the JFactory class/Accessing the current user object|Accessing the current user object]] &lt;br /&gt;
&lt;br /&gt;
== JFactory::getDate() ==&lt;br /&gt;
&lt;br /&gt;
Returns a [[S:MyLanguage/Using the JFactory class/How to use JDate|How to use JDate]] instance, you can also add a time and a timezone offset to it. Without parameters it uses the current time.&lt;br /&gt;
&lt;br /&gt;
== JFactory::getMailer() ==&lt;br /&gt;
&lt;br /&gt;
Provides access to the Joomla Mailer (wrapper around PHPMailer) for sending emails with Joomla.&lt;br /&gt;
&lt;br /&gt;
*See also [[Sending email from extensions]]&lt;br /&gt;
&lt;br /&gt;
== JFactory::getConfig() ==&lt;br /&gt;
&lt;br /&gt;
Returns a registry with the Joomla! configuration file (configuration.php), see JConfig for more details. To access single values you can use &amp;lt;tt&amp;gt;JFactory::getApplication()-&amp;gt;get(&#039;configValue&#039;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*See also Getting global configuration parameters&lt;br /&gt;
&lt;br /&gt;
== JFactory::getSession() ==&lt;br /&gt;
&lt;br /&gt;
Returns the current visitors session. (Make sure Joomla! is called as Webapplication)&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
*[https://api.joomla.org/cms-3/classes/JFactory.html API Docs for JFactory]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
[[Category:JFactory]] &lt;br /&gt;
[[Category:Tutorials]][[Category:Framework]]&lt;br /&gt;
[[Category:Module Development]]&lt;br /&gt;
[[Category:Plugin Development]]&lt;br /&gt;
[[Category:Component Development]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mickmackusa</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Using_the_JFactory_class&amp;diff=635064</id>
		<title>Using the JFactory class</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Using_the_JFactory_class&amp;diff=635064"/>
		<updated>2019-10-19T03:08:12Z</updated>

		<summary type="html">&lt;p&gt;Mickmackusa: /* JFactory::getDbo() */ rewording of description, removed unnecessary parentheses, fixed deadlink, added new relevant link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Top portal heading|color=white-bkgd|icon=magic|icon-color=#5091cd|size=3x|text-color=#333|title=Tutorial&amp;lt;br /&amp;gt;&lt;br /&gt;
Using the JFactory Class}}&lt;br /&gt;
&amp;lt;noinclude&amp;gt;{{Joomla version|version=3.0|time=and after|comment=&amp;lt;series}}&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
{{-}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
JFactory is the Joomla! Platform class, giving you access to the most important (mostly singletons) parts in Joomla. It contains multiple other objects, like the application one or the Joomla! global configuration.&lt;br /&gt;
&lt;br /&gt;
== JFactory::getApplication() ==&lt;br /&gt;
&lt;br /&gt;
Returns the JApplicationCMS, through it you can access for the example do redirects, access the configuration and the input variables, the Menu or enqueue messages which are shown to the user.&lt;br /&gt;
&lt;br /&gt;
*See [[S:MyLanguage/Using the JFactory class/Using the JApplication class|Using the JApplication class]] for more details.&lt;br /&gt;
&lt;br /&gt;
== JFactory::getDocument() ==&lt;br /&gt;
&lt;br /&gt;
Provides access to the current JDocument, with it you can set Meta data, add styles and scripts and more related to the document.&lt;br /&gt;
&lt;br /&gt;
*See [[S:MyLanguage/Using the JFactory class/Adding JavaScript and CSS to the page|Adding JavaScript and CSS to the page]]&lt;br /&gt;
&lt;br /&gt;
== JFactory::getDbo() ==&lt;br /&gt;
&lt;br /&gt;
Returns a database object. [https://api.joomla.org/cms-3/classes/JDatabaseDriver.html JDatabase methods] are executed by chaining to the database object.&lt;br /&gt;
&lt;br /&gt;
Examples:&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-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;$query = JFactory::getDbo()-&amp;gt;getQuery(true);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*See also [https://docs.joomla.org/Selecting_data_using_JDatabase Selecting data using JDatabase]&lt;br /&gt;
&lt;br /&gt;
== JFactory::getUser() ==&lt;br /&gt;
&lt;br /&gt;
Returns the current Joomla! user object (JUser), with it you can access information and methods related to users. It is also created for guests, where the id is zero.&lt;br /&gt;
&lt;br /&gt;
*See [[S:MyLanguage/Using the JFactory class/Accessing the current user object|Accessing the current user object]] &lt;br /&gt;
&lt;br /&gt;
== JFactory::getDate() ==&lt;br /&gt;
&lt;br /&gt;
Returns a [[S:MyLanguage/Using the JFactory class/How to use JDate|How to use JDate]] instance, you can also add a time and a timezone offset to it. Without parameters it uses the current time.&lt;br /&gt;
&lt;br /&gt;
== JFactory::getMailer() ==&lt;br /&gt;
&lt;br /&gt;
Provides access to the Joomla Mailer (wrapper around PHPMailer) for sending emails with Joomla.&lt;br /&gt;
&lt;br /&gt;
*See also [[Sending email from extensions]]&lt;br /&gt;
&lt;br /&gt;
== JFactory::getConfig() ==&lt;br /&gt;
&lt;br /&gt;
Returns a registry with the Joomla! configuration file (configuration.php), see JConfig for more details. To access single values you can use &amp;lt;tt&amp;gt;JFactory::getApplication()-&amp;gt;get(&#039;configValue&#039;)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*See also Getting global configuration parameters&lt;br /&gt;
&lt;br /&gt;
== JFactory::getSession() ==&lt;br /&gt;
&lt;br /&gt;
Returns the current visitors session. (Make sure Joomla! is called as Webapplication)&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
*[https://api.joomla.org/cms-3/classes/JFactory.html API Docs for JFactory]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
[[Category:JFactory]] &lt;br /&gt;
[[Category:Tutorials]][[Category:Framework]]&lt;br /&gt;
[[Category:Module Development]]&lt;br /&gt;
[[Category:Plugin Development]]&lt;br /&gt;
[[Category:Component Development]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mickmackusa</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Secure_coding_guidelines&amp;diff=635049</id>
		<title>Secure coding guidelines</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Secure_coding_guidelines&amp;diff=635049"/>
		<updated>2019-10-19T01:59:10Z</updated>

		<summary type="html">&lt;p&gt;Mickmackusa: /* Secure arrays of integers */ $catId is NOT modified by reference; the return value must overwrite the input variable.  https://joomla.stackexchange.com/a/22898/12352&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Joomla includes many features that help with the task of securing applications and extensions built on it.  You should always use these features if at all possible as they have been tried and tested by the many eyes of the developer community and any updates that might conceivably be required in the future will be automatically available whenever a Joomla update is applied.  What follows is a description of best practice in using the Joomla API to ensure that your extensions are as secure as possible.&lt;br /&gt;
&lt;br /&gt;
==Getting data from the request==&lt;br /&gt;
{{JVer|3.x}} Starting with Joomla version 3.0, [[Retrieving_request_data_using_JInput|JInput]] should be used instead of [[JRequest]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
All input originating from a user must be considered potentially dangerous and must be cleaned before being used.  You should always use the Joomla [[Retrieving_request_data_using_JInput|JInput]] class to retrieve data from the request, rather than the raw $_GET, $_POST or $_REQUEST variables as the [[Retrieving_request_data_using_JInput|JInput]] methods apply input filtering by default. JInput deals with all aspects of the user request in a way that is independent of the request method used.  It can also be used to retrieve cookie data and even server and environment variables. However, it is important to use the correct [[Retrieving_request_data_using_JInput|JInput]] method to ensure maximum security.  It is very easy to just use the [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]] method with default parameters and ignore the fact that in many cases it is possible to apply a more stringent requirement on user input.&lt;br /&gt;
&lt;br /&gt;
It very important to understand that the [[Retrieving_request_data_using_JInput|JInput]] methods are not SQL-aware and further work is required to guard against SQL injection attacks.There is no default value that will be returned if no default is specified in the call the [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]]. If no default is specified and the argument is not present in the request variable then it will return undefined.&lt;br /&gt;
&lt;br /&gt;
Using [[Retrieving_request_data_using_JInput|JInput]] also obviates the need to pay attention to the setting of magic_quotes_gpc. [[Retrieving_request_data_using_JInput|JInput]] does the right thing, regardless of whether magic_quotes_gpc is on or off.  See http://php.net/manual/en/security.magicquotes.php for further information.&lt;br /&gt;
&lt;br /&gt;
When considering user input you should think about the data type you are expecting to retrieve and apply the most stringent form of [[Retrieving_request_data_using_JInput#Getting_Values|JInput]] that is applicable in each case.  In particular, avoid the lazy approach of using [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]] as this will return an array that may contain entries that you did not expect and although each of those entries will have been cleaned, it is often the case that additional filtering could have been applied to some individual arguments.  For example, the get method treats all arguments as strings, whereas it may be possible to restrict some arguments to be integers.&lt;br /&gt;
&lt;br /&gt;
The first three parameters of each of the JInput get methods are the same.  Only the first parameter is mandatory.  In general, the format is&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
    JFactory::getApplication-&amp;gt;input-&amp;gt;&amp;lt;data-source&amp;gt;-&amp;gt;get&amp;lt;type&amp;gt;( &amp;lt;name&amp;gt;, &amp;lt;default&amp;gt; )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| &amp;lt;type&amp;gt; || the data type to be retrieved (see below for the types available).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;name&amp;gt; || the name of the variable to be retrieved (for example, the name of an argument in a URL).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;default&amp;gt; || the default value.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;amp;lt;data-source&amp;amp;gt; || specifies where the variable is to be retrieved from (see below).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following values for &amp;amp;lt;data-source&amp;amp;gt; are supported:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| get || Data submitted in the query part of the URL.&lt;br /&gt;
|-&lt;br /&gt;
| post || Data submitted from form fields.&lt;br /&gt;
|-&lt;br /&gt;
| method || The same as either GET or POST depending on how the request was made.&lt;br /&gt;
|-&lt;br /&gt;
| cookie || Data submitted in cookies.&lt;br /&gt;
|-&lt;br /&gt;
| request || All the GET, POST and COOKIE data combined.  This is the default.&lt;br /&gt;
|-&lt;br /&gt;
| files || Information about files uploaded as part of a POST request.&lt;br /&gt;
|-&lt;br /&gt;
| env || Environment variables (platform-specific).&lt;br /&gt;
|-&lt;br /&gt;
| server || Web server variables (platform-specific).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Notice that the default is REQUEST, which includes cookie data.&lt;br /&gt;
&lt;br /&gt;
The following sections look at each of the data types in more detail.&lt;br /&gt;
&lt;br /&gt;
===Integer===&lt;br /&gt;
The following will accept an integer.  An integer can include a leading minus sign, but a plus sign is not permitted.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$integer = JFactory::getApplication-&amp;gt;input-&amp;gt;getInt( &#039;id&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return the value of the &amp;quot;id&amp;quot; argument from the request (which by default includes all GET, POST and COOKIE data).  The default value is zero.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$integer = JFactory::getApplication-&amp;gt;input-&amp;gt;cookie-&amp;gt;getInt( &#039;myId&#039;, 12 );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return the value of the &amp;quot;myId&amp;quot; variable from a cookie, with a default value of 12.&lt;br /&gt;
&lt;br /&gt;
===Floating point number===&lt;br /&gt;
A floating point number can include a leading minus sign, but not a plus sign.  If the number includes a decimal point, then there must be at least one digit before the decimal point.  For example,&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$float = JFactory::getApplication-&amp;gt;input-&amp;gt;getFloat( &#039;price&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return the value of the &#039;price&#039; argument from the request.  The default is &amp;quot;0.0&amp;quot;.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$float = JFactory::getApplication-&amp;gt;input-&amp;gt;post-&amp;gt;getFloat( &#039;total&#039;, 100.00 );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &#039;total&#039; argument from a POST request (but not a GET), with a default value of 100.00.&lt;br /&gt;
&lt;br /&gt;
===Boolean value===&lt;br /&gt;
Any non-zero value is regarded as being true; zero is false.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$boolean = JFactory::getApplication-&amp;gt;input-&amp;gt;getBool( &#039;show&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return false if the value of the &#039;show&#039; argument in the request is zero, or 1 (true) if the argument is anything else.  The default is false.  Note that any string argument will result in a return value of true, so calling the above with a URL containing &amp;quot;?show=false&amp;quot; will actually return true!&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$boolean = JFactory::getApplication-&amp;gt;input-&amp;gt;get-&amp;gt;getBool( &#039;hide&#039;, true );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &#039;hide&#039; argument from a GET request (but not a POST), with a default value of true.&lt;br /&gt;
&lt;br /&gt;
===Word===&lt;br /&gt;
A word is defined as being a string of alphabetic characters.  The underscore character is permitted as part of a word.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$word = JFactory::getApplication-&amp;gt;input-&amp;gt;cookie-&amp;gt;getWord( &#039;search-word&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &#039;search-word&#039; argument from the request.  The default is an empty string.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$word = JFactory::getApplication-&amp;gt;input-&amp;gt;cookie-&amp;gt;getWord( &#039;keyword&#039;, &#039;&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &#039;keyword&#039; variable from a cookie, with the default being an empty string.&lt;br /&gt;
&lt;br /&gt;
===Command===&lt;br /&gt;
A command is like a word but a wider range of characters is permitted.  Allowed characters are: all alphanumeric characters, dot, dash (hyphen) and underscore.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$command = JFactory::getApplication-&amp;gt;input-&amp;gt;getCmd( &#039;option&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;option&amp;quot; argument from the request.  The default value is an empty string.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$command = JFactory::getApplication-&amp;gt;input-&amp;gt;post-&amp;gt;getCmd( &#039;controller&#039;, &#039;view&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;controller&amp;quot; argument from a POST request (but not a GET), with a default value of &#039;view&#039;.&lt;br /&gt;
&lt;br /&gt;
===String===&lt;br /&gt;
The string type allows a much wider range of input characters.  It also takes an optional fourth argument specifying some additional mask options.  See [[#Filter options]] for information on the available masks.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$string = JFactory::getApplication-&amp;gt;input-&amp;gt;getString( &#039;description&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;description&amp;quot; argument from the request.  The default value is an empty string.  The input will have whitespace removed from the left and right ends and any HTML tags will be removed.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$string = JFactory::getApplication-&amp;gt;input-&amp;gt;getString( &#039;text&#039;, &#039;&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;text&amp;quot; argument from the request..  The default value is an empty string.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$string = JFactory::getApplication-&amp;gt;input-&amp;gt;getString( &#039;template&#039;, &#039;&amp;lt;html /&amp;gt;&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;template&amp;quot; argument from the request.  The default value is &#039;&amp;lt;html /&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
===JSON String===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$json = JFactory::getApplication-&amp;gt;input-&amp;gt;json-&amp;gt;get( &#039;var_name&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Generic and other data types===&lt;br /&gt;
If the above methods do not meet your needs, there is a small number of additional filter types which you can use by calling the [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]] method directly.  The syntax is:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getApplication-&amp;gt;input-&amp;gt;get( &amp;lt;name&amp;gt;, &amp;lt;default&amp;gt;, &amp;lt;type&amp;gt; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| &amp;lt;name&amp;gt; || the name of the variable to be retrieved (for example, the name of an argument in a URL).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;default&amp;gt; || the default value.  There is no default value that will be returned if no default is specified in the call the [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]].   If no default is specified and the argument is not present in the request variable then it will return undefined.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;type&amp;gt; || specifies the data type expected (see below).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first three arguments are the same as for the more specific methods described earlier.  Only the first argument is mandatory.&lt;br /&gt;
&lt;br /&gt;
Allowed values of the &amp;lt;type&amp;gt;, which is case-insensitive, are as follows:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| INT, INTEGER || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getInt]].&lt;br /&gt;
|-&lt;br /&gt;
| UINT || Get an unsigned integer. Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getUint]].&lt;br /&gt;
|-&lt;br /&gt;
| FLOAT, DOUBLE || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getFloat]].&lt;br /&gt;
|-&lt;br /&gt;
| BOOL, BOOLEAN || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getBool]].&lt;br /&gt;
|-&lt;br /&gt;
| WORD || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getWord]].&lt;br /&gt;
|-&lt;br /&gt;
| ALNUM || Allow only alphanumeric characters (a-z, A-Z, 0-9). Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getAlnum]].&lt;br /&gt;
|-&lt;br /&gt;
| CMD || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getCmd]].&lt;br /&gt;
|-&lt;br /&gt;
| BASE64 || Allow only those characters that could be present in a base64-encoded string (ie. a-z, A-Z, 0-9, /, + and =). Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getBase64]].&lt;br /&gt;
|-&lt;br /&gt;
| STRING || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getString]].&lt;br /&gt;
|-&lt;br /&gt;
| ARRAY || Source is not filtered but is cast to array type.&lt;br /&gt;
|-&lt;br /&gt;
| HTML || A sanitised string. Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getHtml]].&lt;br /&gt;
|-&lt;br /&gt;
| PATH || Valid pathname regex that filters out common attacks.  For example, any path beginning with a &amp;quot;/&amp;quot; will return an empty string.  Simliarly, any path containing &amp;quot;/./&amp;quot; or &amp;quot;/../&amp;quot; will return an empty string.  Dots within filenames are okay though. Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getPath]].&lt;br /&gt;
|-&lt;br /&gt;
| USERNAME || Removes control characters (0x00 - 0x1F), 0x7F, &amp;lt;, &amp;gt;, &amp;quot;, &#039;, % and &amp;amp;. Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getUsername]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Filter options===&lt;br /&gt;
All input values can be filtered using JFilterInput-&amp;gt;clean.&lt;br /&gt;
&lt;br /&gt;
Filter an array of values.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$data = JFactory::getApplication()-&amp;gt;input-&amp;gt;post-&amp;gt;get(&#039;data&#039;, array(), &#039;array&#039;);&lt;br /&gt;
$filter = JFilterInput::getInstance();&lt;br /&gt;
&lt;br /&gt;
foreach ($data as $value)&lt;br /&gt;
{&lt;br /&gt;
	$array[] = $filter-&amp;gt;clean($value, &#039;string&#039;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
For more filter types see [https://github.com/joomla/joomla-cms/blob/master/libraries/joomla/filter/input.php#L115 JFilterInput source].&lt;br /&gt;
&lt;br /&gt;
Options listed bellow available only in deprecated [[JRequest]] library.&lt;br /&gt;
Allowed values of &amp;lt;options&amp;gt; are as follows (none of these are applied by default):&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| JREQUEST_NOTRIM || Does not remove whitespace from the start and ends of strings.&lt;br /&gt;
|-&lt;br /&gt;
| JREQUEST_ALLOWRAW || Does not do any filtering at all.  Use with extreme caution.&lt;br /&gt;
|-&lt;br /&gt;
| JREQUEST_ALLOWHTML || Does not remove HTML from string inputs.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Masks can be combined by logically OR&#039;ing them.  If no filter options are specified, then by default, whitespace is trimmed and HTML is removed.&lt;br /&gt;
&lt;br /&gt;
===File uploads===&lt;br /&gt;
Web servers already have a good deal of security around handling file uploads, but it is still necessary to take additional steps to ensure that file names and paths cannot be abused.  A simplified form which requests a file to be uploaded looks like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;index.php?option=com_mycomponent/form_handler.php&amp;quot;  method=&amp;quot;post&amp;quot; enctype=&amp;quot;multipart/form-data&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;input type=&amp;quot;file&amp;quot; name=&amp;quot;Filedata&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;input type=&amp;quot;submit&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
On clicking the submit button, the browser will upload the file in a POST request, passing control to Joomla which will call &amp;quot;components/com_mycomponent/form_handler.php&amp;quot;.  This will include code like the following.  The variable $somepath must be set to some path where the web server has permission to create files.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;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;
// Get the file data array from the request.&lt;br /&gt;
$file = JFactory::getApplication-&amp;gt;input-&amp;gt;get( &#039;Filedata&#039;, &#039;&#039;, &#039;files&#039;, &#039;array&#039; );&lt;br /&gt;
&lt;br /&gt;
// Make the file name safe.&lt;br /&gt;
jimport(&#039;joomla.filesystem.file&#039;);&lt;br /&gt;
$file[&#039;name&#039;] = JFile::makeSafe($file[&#039;name&#039;]);&lt;br /&gt;
&lt;br /&gt;
// Move the uploaded file into a permanent location.&lt;br /&gt;
if (isset( $file[&#039;name&#039;] )) {&lt;br /&gt;
&lt;br /&gt;
    // Make sure that the full file path is safe.&lt;br /&gt;
    $filepath = JPath::clean( $somepath.&#039;/&#039;.strtolower( $file[&#039;name&#039;] ) );&lt;br /&gt;
&lt;br /&gt;
    // Move the uploaded file.&lt;br /&gt;
    JFile::upload( $file[&#039;tmp_name&#039;], $filepath );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Saving a request variable into user state===&lt;br /&gt;
Because setting a user state variable from a variable in the request is such a common operation, there is an API method to make the task easier.  This is generally safe to use because it calls [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]] to obtain the input from the request, but remember that none of the input filtering calls will protect against SQL injection attempts.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$app = JFactory::getApplication();&lt;br /&gt;
$app-&amp;gt;getUserStateFromRequest( &amp;lt;key&amp;gt;, &amp;lt;name&amp;gt;, &amp;lt;default&amp;gt;, &amp;lt;type&amp;gt; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
where&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| &amp;lt;key&amp;gt; || the name of the variable in the user state.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;name&amp;gt; || the name of the request variable (same as the first argument of a [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]] call).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;default&amp;gt; || the default value to be assigned to the user state variable if the request variable is absent.  The default is null.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;type&amp;gt; || the type of variable expected.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, getting an integer variable called &#039;id&#039; from the request with a default value of 0, then saving it into a session variable called &#039;myid&#039; can be done like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$app = JFactory::getApplication();&lt;br /&gt;
$app-&amp;gt;getUserStateFromRequest( &#039;myid&#039;, &#039;id, 0, &#039;int&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
instead of something like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$app = JFactory::getApplication();&lt;br /&gt;
$app-&amp;gt;setUserState( &#039;myid&#039;, $app-&amp;gt;input-&amp;gt;getInt( &#039;id&#039;, 0 ) );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Constructing SQL queries==&lt;br /&gt;
One of the most common forms of attack on web applications is SQL injection, where the aim of the attacker is to change a database query by exploiting a poorly filtered input variable.  Injecting modified SQL statements into the database can damage data or reveal private information.  It is important to ensure that when SQL statements are constructed, they are correctly escaped and quoted so that bad input data cannot result in a bad SQL statement. You cannot rely on the [[Retrieving_request_data_using_JInput|JInput]] methods to do this as they are not SQL-aware.&lt;br /&gt;
&lt;br /&gt;
===Secure integers and the rest of numeric values===&lt;br /&gt;
With the MySQL database, numeric fields should not be quoted, so it is important that they be typecast instead.  Failure to do this will leave your code vulnerable to an attacker inserting a string containing SQL data.&lt;br /&gt;
&lt;br /&gt;
Depending on the type, numeric types are cast like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// For SQL data types: INT, INTEGER, TINYINT, SMALLINT, MEDIUMINT, BIGINT, YEAR&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `id`=&#039; . (int) $id;&lt;br /&gt;
&lt;br /&gt;
// For SQL data types: FLOAT, DOUBLE&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `id`=&#039; . (float) $id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
It&#039;s a good idea to get into the habit of always typecasting integers like this even if the variable was previously obtained using JInput-&amp;gt;getInt. Further information on SQL injection attacks can be found here: http://php.net/manual/en/security.database.sql-injection.php and here: [[Retrieving_request_data_using_JInput#Getting_Values]].&lt;br /&gt;
&lt;br /&gt;
===Secure strings===&lt;br /&gt;
In the examples that follow it is assumed that $db is an instance of a Joomla database object.  This can always be obtained from [[JFactory]] using&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDBO();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Strings should always be escaped before being used in an SQL statement.  This is actually very simple as the [[JDatabase/quote|JDatabase-&amp;gt;quote]] method escapes everything for you.  You can also use the [[JDatabase/escape|JDatabase-&amp;gt;escape]] method directly.  The following statements are equivalent:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `field` = &#039; . $db-&amp;gt;quote( $db-&amp;gt;escape( $field ), false );&lt;br /&gt;
&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `field` = &#039; . $db-&amp;gt;quote( $field );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
===Secure on search===&lt;br /&gt;
Special attention should be paid to LIKE clauses which contain the % wildcard character as these require special escaping in order to avoid possible denial of service attacks.  LIKE clauses can be handled like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Construct the search term by escaping the user-supplied string and, if required, adding the % wildcard characters manually.&lt;br /&gt;
$search = &#039;%&#039; . $db-&amp;gt;escape( $search, true ) . &#039;%&#039;;&lt;br /&gt;
&lt;br /&gt;
// Construct the SQL query, being careful to suppress the default behaviour of Quote so as to prevent double-escaping.&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `field` LIKE &#039; . $db-&amp;gt;quote( $search, false );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Secure dates===&lt;br /&gt;
If data is to be entered into a datetime column then you can use the Joomla API to ensure a valid date format:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$date = JFactory::getDate( $mydate );&lt;br /&gt;
$query = &#039;UPDATE #__table SET `date` = &#039; . $db-&amp;gt;quote( $date-&amp;gt;toMySQL(), false );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Note that it is necessary to suppress database escaping as legitimate dates may contain characters that should not be escaped.&lt;br /&gt;
&lt;br /&gt;
===Secure field names===&lt;br /&gt;
In the comparatively rare case where a field name is a variable, that should also be quoted using an API call:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE &#039; . $db-&amp;gt;quoteName( $field-&amp;gt;name ) . &#039;=&#039; . $db-&amp;gt;quote( $field-&amp;gt;value );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Secure arrays of integers===&lt;br /&gt;
When you have an array of ids, typically used for IN() queries, you have to sanitise it also with JArrayHelper::toInteger($cid); before imploding: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
$catId = JArrayHelper::toInteger($catId);&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;x.category_id&#039;) . &#039; IN (&#039; . implode(&#039;,&#039;, $catId) . &#039;)&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Short aliases of Quote and QuoteName===&lt;br /&gt;
Shorter alternatives to the quote methods may also be used.  The following statements are equivalent:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE &#039; . $db-&amp;gt;quoteName( $field-&amp;gt;name ) . &#039;=&#039; . $db-&amp;gt;quote( $field-&amp;gt;value );&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE &#039; . $db-&amp;gt;qn( $field-&amp;gt;name ) . &#039;=&#039; . $db-&amp;gt;q( $field-&amp;gt;value );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Securing forms==&lt;br /&gt;
Apart from cleaning input variables as described above, you can also implement a simple technique which makes it more difficult for a cross-site request forgery attack (CSRF) to succeed. This involves adding a randomly-generated unique token to the form which is checked against a copy of the token held in the user&#039;s session.  By checking that the submitted token matches the one contained in the stored session, it is possible to tie a rendered form to the request variables presented.&lt;br /&gt;
&lt;br /&gt;
In POST forms you should add a hidden token field using:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo JHTML::_( &#039;form.token&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This outputs the token as a hidden form field looking like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;8cb24ae69ffd7828ccecbcf06056e6fc&amp;quot; value=&amp;quot;1&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and places a copy of the token into the user&#039;s session, for later checking.&lt;br /&gt;
&lt;br /&gt;
If you need to add the token to a URL rather than a form then you can use something like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo JRoute::_( &#039;index.php?option=com_mycomponent&amp;amp;&#039; . JSession::getFormToken() . &#039;=1&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the most common scenario, you will want to check the token following a POST to the form handler.  This can be done by adding this line of code to form handler:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JSession::checkToken() or die( JText::_( &#039;Invalid Token&#039; ) );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to pass the token in a GET request then you can check it like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JSession::checkToken( &#039;get&#039; ) or die( JText::_( &#039;Invalid Token&#039; ) );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In both cases the code will die if the token is omitted from the request, or the submitted token does not match the session token.  If the token is correct but has expired, then [[JSession/checkToken|JSession::checkToken]] will automatically redirect to the site front page.&lt;br /&gt;
&lt;br /&gt;
==Cleaning filesystem paths==&lt;br /&gt;
If there is any possibility that a filesystem path might be constructed using data that originated from user input, then the path must be cleaned and checked before being used.  This can be done quite simply like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JPath::check( $path );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This will raise an error and terminate Joomla if the path contains a &amp;quot;..&amp;quot; or leads to a location outside the Joomla root directory.  If you want to deal with the error yourself without terminating the application, then you can use code like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$path = JPath::clean( $path );&lt;br /&gt;
if (strpos( $path, JPath::clean( JPATH_ROOT ) ) !== 0) {&lt;br /&gt;
    // Handle the error here.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The [[JPath:clean]] method can be used in your own code too.  It merely removes leading and trailing whitespace and replace double slashes and backslashes with the standard directory separator.&lt;br /&gt;
&lt;br /&gt;
==Cleaning filesystem file names==&lt;br /&gt;
As with filesystem paths, if there is any possibility that a file name might be constructed using user-originated data, then the file name must be cleaned and checked before use.  This can be done like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
jimport(&#039;joomla.filesystem.file&#039;);&lt;br /&gt;
$clean = JFile::makeSafe( $unclean );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This method removes sequences of two or more &amp;quot;.&amp;quot; characters and any character that is not alphabetic, numeric or a dot, dash or underscore character.  If there is a leading dot then that is removed too.&lt;br /&gt;
[[Category:Development]][[Category:Security]]&lt;/div&gt;</summary>
		<author><name>Mickmackusa</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Secure_coding_guidelines&amp;diff=635045</id>
		<title>Secure coding guidelines</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Secure_coding_guidelines&amp;diff=635045"/>
		<updated>2019-10-19T01:49:37Z</updated>

		<summary type="html">&lt;p&gt;Mickmackusa: /* Short aliases of Quote and QuoteName */  fixed syntax error regarding property arrow&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Joomla includes many features that help with the task of securing applications and extensions built on it.  You should always use these features if at all possible as they have been tried and tested by the many eyes of the developer community and any updates that might conceivably be required in the future will be automatically available whenever a Joomla update is applied.  What follows is a description of best practice in using the Joomla API to ensure that your extensions are as secure as possible.&lt;br /&gt;
&lt;br /&gt;
==Getting data from the request==&lt;br /&gt;
{{JVer|3.x}} Starting with Joomla version 3.0, [[Retrieving_request_data_using_JInput|JInput]] should be used instead of [[JRequest]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
All input originating from a user must be considered potentially dangerous and must be cleaned before being used.  You should always use the Joomla [[Retrieving_request_data_using_JInput|JInput]] class to retrieve data from the request, rather than the raw $_GET, $_POST or $_REQUEST variables as the [[Retrieving_request_data_using_JInput|JInput]] methods apply input filtering by default. JInput deals with all aspects of the user request in a way that is independent of the request method used.  It can also be used to retrieve cookie data and even server and environment variables. However, it is important to use the correct [[Retrieving_request_data_using_JInput|JInput]] method to ensure maximum security.  It is very easy to just use the [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]] method with default parameters and ignore the fact that in many cases it is possible to apply a more stringent requirement on user input.&lt;br /&gt;
&lt;br /&gt;
It very important to understand that the [[Retrieving_request_data_using_JInput|JInput]] methods are not SQL-aware and further work is required to guard against SQL injection attacks.There is no default value that will be returned if no default is specified in the call the [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]]. If no default is specified and the argument is not present in the request variable then it will return undefined.&lt;br /&gt;
&lt;br /&gt;
Using [[Retrieving_request_data_using_JInput|JInput]] also obviates the need to pay attention to the setting of magic_quotes_gpc. [[Retrieving_request_data_using_JInput|JInput]] does the right thing, regardless of whether magic_quotes_gpc is on or off.  See http://php.net/manual/en/security.magicquotes.php for further information.&lt;br /&gt;
&lt;br /&gt;
When considering user input you should think about the data type you are expecting to retrieve and apply the most stringent form of [[Retrieving_request_data_using_JInput#Getting_Values|JInput]] that is applicable in each case.  In particular, avoid the lazy approach of using [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]] as this will return an array that may contain entries that you did not expect and although each of those entries will have been cleaned, it is often the case that additional filtering could have been applied to some individual arguments.  For example, the get method treats all arguments as strings, whereas it may be possible to restrict some arguments to be integers.&lt;br /&gt;
&lt;br /&gt;
The first three parameters of each of the JInput get methods are the same.  Only the first parameter is mandatory.  In general, the format is&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
    JFactory::getApplication-&amp;gt;input-&amp;gt;&amp;lt;data-source&amp;gt;-&amp;gt;get&amp;lt;type&amp;gt;( &amp;lt;name&amp;gt;, &amp;lt;default&amp;gt; )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| &amp;lt;type&amp;gt; || the data type to be retrieved (see below for the types available).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;name&amp;gt; || the name of the variable to be retrieved (for example, the name of an argument in a URL).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;default&amp;gt; || the default value.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;amp;lt;data-source&amp;amp;gt; || specifies where the variable is to be retrieved from (see below).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following values for &amp;amp;lt;data-source&amp;amp;gt; are supported:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| get || Data submitted in the query part of the URL.&lt;br /&gt;
|-&lt;br /&gt;
| post || Data submitted from form fields.&lt;br /&gt;
|-&lt;br /&gt;
| method || The same as either GET or POST depending on how the request was made.&lt;br /&gt;
|-&lt;br /&gt;
| cookie || Data submitted in cookies.&lt;br /&gt;
|-&lt;br /&gt;
| request || All the GET, POST and COOKIE data combined.  This is the default.&lt;br /&gt;
|-&lt;br /&gt;
| files || Information about files uploaded as part of a POST request.&lt;br /&gt;
|-&lt;br /&gt;
| env || Environment variables (platform-specific).&lt;br /&gt;
|-&lt;br /&gt;
| server || Web server variables (platform-specific).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Notice that the default is REQUEST, which includes cookie data.&lt;br /&gt;
&lt;br /&gt;
The following sections look at each of the data types in more detail.&lt;br /&gt;
&lt;br /&gt;
===Integer===&lt;br /&gt;
The following will accept an integer.  An integer can include a leading minus sign, but a plus sign is not permitted.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$integer = JFactory::getApplication-&amp;gt;input-&amp;gt;getInt( &#039;id&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return the value of the &amp;quot;id&amp;quot; argument from the request (which by default includes all GET, POST and COOKIE data).  The default value is zero.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$integer = JFactory::getApplication-&amp;gt;input-&amp;gt;cookie-&amp;gt;getInt( &#039;myId&#039;, 12 );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return the value of the &amp;quot;myId&amp;quot; variable from a cookie, with a default value of 12.&lt;br /&gt;
&lt;br /&gt;
===Floating point number===&lt;br /&gt;
A floating point number can include a leading minus sign, but not a plus sign.  If the number includes a decimal point, then there must be at least one digit before the decimal point.  For example,&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$float = JFactory::getApplication-&amp;gt;input-&amp;gt;getFloat( &#039;price&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return the value of the &#039;price&#039; argument from the request.  The default is &amp;quot;0.0&amp;quot;.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$float = JFactory::getApplication-&amp;gt;input-&amp;gt;post-&amp;gt;getFloat( &#039;total&#039;, 100.00 );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &#039;total&#039; argument from a POST request (but not a GET), with a default value of 100.00.&lt;br /&gt;
&lt;br /&gt;
===Boolean value===&lt;br /&gt;
Any non-zero value is regarded as being true; zero is false.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$boolean = JFactory::getApplication-&amp;gt;input-&amp;gt;getBool( &#039;show&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return false if the value of the &#039;show&#039; argument in the request is zero, or 1 (true) if the argument is anything else.  The default is false.  Note that any string argument will result in a return value of true, so calling the above with a URL containing &amp;quot;?show=false&amp;quot; will actually return true!&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$boolean = JFactory::getApplication-&amp;gt;input-&amp;gt;get-&amp;gt;getBool( &#039;hide&#039;, true );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &#039;hide&#039; argument from a GET request (but not a POST), with a default value of true.&lt;br /&gt;
&lt;br /&gt;
===Word===&lt;br /&gt;
A word is defined as being a string of alphabetic characters.  The underscore character is permitted as part of a word.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$word = JFactory::getApplication-&amp;gt;input-&amp;gt;cookie-&amp;gt;getWord( &#039;search-word&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &#039;search-word&#039; argument from the request.  The default is an empty string.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$word = JFactory::getApplication-&amp;gt;input-&amp;gt;cookie-&amp;gt;getWord( &#039;keyword&#039;, &#039;&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &#039;keyword&#039; variable from a cookie, with the default being an empty string.&lt;br /&gt;
&lt;br /&gt;
===Command===&lt;br /&gt;
A command is like a word but a wider range of characters is permitted.  Allowed characters are: all alphanumeric characters, dot, dash (hyphen) and underscore.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$command = JFactory::getApplication-&amp;gt;input-&amp;gt;getCmd( &#039;option&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;option&amp;quot; argument from the request.  The default value is an empty string.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$command = JFactory::getApplication-&amp;gt;input-&amp;gt;post-&amp;gt;getCmd( &#039;controller&#039;, &#039;view&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;controller&amp;quot; argument from a POST request (but not a GET), with a default value of &#039;view&#039;.&lt;br /&gt;
&lt;br /&gt;
===String===&lt;br /&gt;
The string type allows a much wider range of input characters.  It also takes an optional fourth argument specifying some additional mask options.  See [[#Filter options]] for information on the available masks.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$string = JFactory::getApplication-&amp;gt;input-&amp;gt;getString( &#039;description&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;description&amp;quot; argument from the request.  The default value is an empty string.  The input will have whitespace removed from the left and right ends and any HTML tags will be removed.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$string = JFactory::getApplication-&amp;gt;input-&amp;gt;getString( &#039;text&#039;, &#039;&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;text&amp;quot; argument from the request..  The default value is an empty string.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$string = JFactory::getApplication-&amp;gt;input-&amp;gt;getString( &#039;template&#039;, &#039;&amp;lt;html /&amp;gt;&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;template&amp;quot; argument from the request.  The default value is &#039;&amp;lt;html /&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
===JSON String===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$json = JFactory::getApplication-&amp;gt;input-&amp;gt;json-&amp;gt;get( &#039;var_name&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Generic and other data types===&lt;br /&gt;
If the above methods do not meet your needs, there is a small number of additional filter types which you can use by calling the [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]] method directly.  The syntax is:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getApplication-&amp;gt;input-&amp;gt;get( &amp;lt;name&amp;gt;, &amp;lt;default&amp;gt;, &amp;lt;type&amp;gt; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| &amp;lt;name&amp;gt; || the name of the variable to be retrieved (for example, the name of an argument in a URL).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;default&amp;gt; || the default value.  There is no default value that will be returned if no default is specified in the call the [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]].   If no default is specified and the argument is not present in the request variable then it will return undefined.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;type&amp;gt; || specifies the data type expected (see below).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first three arguments are the same as for the more specific methods described earlier.  Only the first argument is mandatory.&lt;br /&gt;
&lt;br /&gt;
Allowed values of the &amp;lt;type&amp;gt;, which is case-insensitive, are as follows:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| INT, INTEGER || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getInt]].&lt;br /&gt;
|-&lt;br /&gt;
| UINT || Get an unsigned integer. Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getUint]].&lt;br /&gt;
|-&lt;br /&gt;
| FLOAT, DOUBLE || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getFloat]].&lt;br /&gt;
|-&lt;br /&gt;
| BOOL, BOOLEAN || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getBool]].&lt;br /&gt;
|-&lt;br /&gt;
| WORD || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getWord]].&lt;br /&gt;
|-&lt;br /&gt;
| ALNUM || Allow only alphanumeric characters (a-z, A-Z, 0-9). Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getAlnum]].&lt;br /&gt;
|-&lt;br /&gt;
| CMD || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getCmd]].&lt;br /&gt;
|-&lt;br /&gt;
| BASE64 || Allow only those characters that could be present in a base64-encoded string (ie. a-z, A-Z, 0-9, /, + and =). Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getBase64]].&lt;br /&gt;
|-&lt;br /&gt;
| STRING || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getString]].&lt;br /&gt;
|-&lt;br /&gt;
| ARRAY || Source is not filtered but is cast to array type.&lt;br /&gt;
|-&lt;br /&gt;
| HTML || A sanitised string. Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getHtml]].&lt;br /&gt;
|-&lt;br /&gt;
| PATH || Valid pathname regex that filters out common attacks.  For example, any path beginning with a &amp;quot;/&amp;quot; will return an empty string.  Simliarly, any path containing &amp;quot;/./&amp;quot; or &amp;quot;/../&amp;quot; will return an empty string.  Dots within filenames are okay though. Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getPath]].&lt;br /&gt;
|-&lt;br /&gt;
| USERNAME || Removes control characters (0x00 - 0x1F), 0x7F, &amp;lt;, &amp;gt;, &amp;quot;, &#039;, % and &amp;amp;. Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getUsername]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Filter options===&lt;br /&gt;
All input values can be filtered using JFilterInput-&amp;gt;clean.&lt;br /&gt;
&lt;br /&gt;
Filter an array of values.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$data = JFactory::getApplication()-&amp;gt;input-&amp;gt;post-&amp;gt;get(&#039;data&#039;, array(), &#039;array&#039;);&lt;br /&gt;
$filter = JFilterInput::getInstance();&lt;br /&gt;
&lt;br /&gt;
foreach ($data as $value)&lt;br /&gt;
{&lt;br /&gt;
	$array[] = $filter-&amp;gt;clean($value, &#039;string&#039;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
For more filter types see [https://github.com/joomla/joomla-cms/blob/master/libraries/joomla/filter/input.php#L115 JFilterInput source].&lt;br /&gt;
&lt;br /&gt;
Options listed bellow available only in deprecated [[JRequest]] library.&lt;br /&gt;
Allowed values of &amp;lt;options&amp;gt; are as follows (none of these are applied by default):&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| JREQUEST_NOTRIM || Does not remove whitespace from the start and ends of strings.&lt;br /&gt;
|-&lt;br /&gt;
| JREQUEST_ALLOWRAW || Does not do any filtering at all.  Use with extreme caution.&lt;br /&gt;
|-&lt;br /&gt;
| JREQUEST_ALLOWHTML || Does not remove HTML from string inputs.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Masks can be combined by logically OR&#039;ing them.  If no filter options are specified, then by default, whitespace is trimmed and HTML is removed.&lt;br /&gt;
&lt;br /&gt;
===File uploads===&lt;br /&gt;
Web servers already have a good deal of security around handling file uploads, but it is still necessary to take additional steps to ensure that file names and paths cannot be abused.  A simplified form which requests a file to be uploaded looks like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;index.php?option=com_mycomponent/form_handler.php&amp;quot;  method=&amp;quot;post&amp;quot; enctype=&amp;quot;multipart/form-data&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;input type=&amp;quot;file&amp;quot; name=&amp;quot;Filedata&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;input type=&amp;quot;submit&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
On clicking the submit button, the browser will upload the file in a POST request, passing control to Joomla which will call &amp;quot;components/com_mycomponent/form_handler.php&amp;quot;.  This will include code like the following.  The variable $somepath must be set to some path where the web server has permission to create files.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;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;
// Get the file data array from the request.&lt;br /&gt;
$file = JFactory::getApplication-&amp;gt;input-&amp;gt;get( &#039;Filedata&#039;, &#039;&#039;, &#039;files&#039;, &#039;array&#039; );&lt;br /&gt;
&lt;br /&gt;
// Make the file name safe.&lt;br /&gt;
jimport(&#039;joomla.filesystem.file&#039;);&lt;br /&gt;
$file[&#039;name&#039;] = JFile::makeSafe($file[&#039;name&#039;]);&lt;br /&gt;
&lt;br /&gt;
// Move the uploaded file into a permanent location.&lt;br /&gt;
if (isset( $file[&#039;name&#039;] )) {&lt;br /&gt;
&lt;br /&gt;
    // Make sure that the full file path is safe.&lt;br /&gt;
    $filepath = JPath::clean( $somepath.&#039;/&#039;.strtolower( $file[&#039;name&#039;] ) );&lt;br /&gt;
&lt;br /&gt;
    // Move the uploaded file.&lt;br /&gt;
    JFile::upload( $file[&#039;tmp_name&#039;], $filepath );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Saving a request variable into user state===&lt;br /&gt;
Because setting a user state variable from a variable in the request is such a common operation, there is an API method to make the task easier.  This is generally safe to use because it calls [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]] to obtain the input from the request, but remember that none of the input filtering calls will protect against SQL injection attempts.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$app = JFactory::getApplication();&lt;br /&gt;
$app-&amp;gt;getUserStateFromRequest( &amp;lt;key&amp;gt;, &amp;lt;name&amp;gt;, &amp;lt;default&amp;gt;, &amp;lt;type&amp;gt; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
where&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| &amp;lt;key&amp;gt; || the name of the variable in the user state.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;name&amp;gt; || the name of the request variable (same as the first argument of a [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]] call).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;default&amp;gt; || the default value to be assigned to the user state variable if the request variable is absent.  The default is null.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;type&amp;gt; || the type of variable expected.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, getting an integer variable called &#039;id&#039; from the request with a default value of 0, then saving it into a session variable called &#039;myid&#039; can be done like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$app = JFactory::getApplication();&lt;br /&gt;
$app-&amp;gt;getUserStateFromRequest( &#039;myid&#039;, &#039;id, 0, &#039;int&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
instead of something like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$app = JFactory::getApplication();&lt;br /&gt;
$app-&amp;gt;setUserState( &#039;myid&#039;, $app-&amp;gt;input-&amp;gt;getInt( &#039;id&#039;, 0 ) );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Constructing SQL queries==&lt;br /&gt;
One of the most common forms of attack on web applications is SQL injection, where the aim of the attacker is to change a database query by exploiting a poorly filtered input variable.  Injecting modified SQL statements into the database can damage data or reveal private information.  It is important to ensure that when SQL statements are constructed, they are correctly escaped and quoted so that bad input data cannot result in a bad SQL statement. You cannot rely on the [[Retrieving_request_data_using_JInput|JInput]] methods to do this as they are not SQL-aware.&lt;br /&gt;
&lt;br /&gt;
===Secure integers and the rest of numeric values===&lt;br /&gt;
With the MySQL database, numeric fields should not be quoted, so it is important that they be typecast instead.  Failure to do this will leave your code vulnerable to an attacker inserting a string containing SQL data.&lt;br /&gt;
&lt;br /&gt;
Depending on the type, numeric types are cast like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// For SQL data types: INT, INTEGER, TINYINT, SMALLINT, MEDIUMINT, BIGINT, YEAR&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `id`=&#039; . (int) $id;&lt;br /&gt;
&lt;br /&gt;
// For SQL data types: FLOAT, DOUBLE&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `id`=&#039; . (float) $id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
It&#039;s a good idea to get into the habit of always typecasting integers like this even if the variable was previously obtained using JInput-&amp;gt;getInt. Further information on SQL injection attacks can be found here: http://php.net/manual/en/security.database.sql-injection.php and here: [[Retrieving_request_data_using_JInput#Getting_Values]].&lt;br /&gt;
&lt;br /&gt;
===Secure strings===&lt;br /&gt;
In the examples that follow it is assumed that $db is an instance of a Joomla database object.  This can always be obtained from [[JFactory]] using&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDBO();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Strings should always be escaped before being used in an SQL statement.  This is actually very simple as the [[JDatabase/quote|JDatabase-&amp;gt;quote]] method escapes everything for you.  You can also use the [[JDatabase/escape|JDatabase-&amp;gt;escape]] method directly.  The following statements are equivalent:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `field` = &#039; . $db-&amp;gt;quote( $db-&amp;gt;escape( $field ), false );&lt;br /&gt;
&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `field` = &#039; . $db-&amp;gt;quote( $field );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
===Secure on search===&lt;br /&gt;
Special attention should be paid to LIKE clauses which contain the % wildcard character as these require special escaping in order to avoid possible denial of service attacks.  LIKE clauses can be handled like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Construct the search term by escaping the user-supplied string and, if required, adding the % wildcard characters manually.&lt;br /&gt;
$search = &#039;%&#039; . $db-&amp;gt;escape( $search, true ) . &#039;%&#039;;&lt;br /&gt;
&lt;br /&gt;
// Construct the SQL query, being careful to suppress the default behaviour of Quote so as to prevent double-escaping.&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `field` LIKE &#039; . $db-&amp;gt;quote( $search, false );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Secure dates===&lt;br /&gt;
If data is to be entered into a datetime column then you can use the Joomla API to ensure a valid date format:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$date = JFactory::getDate( $mydate );&lt;br /&gt;
$query = &#039;UPDATE #__table SET `date` = &#039; . $db-&amp;gt;quote( $date-&amp;gt;toMySQL(), false );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Note that it is necessary to suppress database escaping as legitimate dates may contain characters that should not be escaped.&lt;br /&gt;
&lt;br /&gt;
===Secure field names===&lt;br /&gt;
In the comparatively rare case where a field name is a variable, that should also be quoted using an API call:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE &#039; . $db-&amp;gt;quoteName( $field-&amp;gt;name ) . &#039;=&#039; . $db-&amp;gt;quote( $field-&amp;gt;value );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Secure arrays of integers===&lt;br /&gt;
When you have an array of ids, typically used for IN() queries, you have to sanitise it also with JArrayHelper::toInteger($cid); before imploding: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
JArrayHelper::toInteger($catId);&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;x.category_id&#039;) . &#039; IN (&#039; . implode(&#039;,&#039;, $catId) . &#039;)&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Short aliases of Quote and QuoteName===&lt;br /&gt;
Shorter alternatives to the quote methods may also be used.  The following statements are equivalent:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE &#039; . $db-&amp;gt;quoteName( $field-&amp;gt;name ) . &#039;=&#039; . $db-&amp;gt;quote( $field-&amp;gt;value );&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE &#039; . $db-&amp;gt;qn( $field-&amp;gt;name ) . &#039;=&#039; . $db-&amp;gt;q( $field-&amp;gt;value );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Securing forms==&lt;br /&gt;
Apart from cleaning input variables as described above, you can also implement a simple technique which makes it more difficult for a cross-site request forgery attack (CSRF) to succeed. This involves adding a randomly-generated unique token to the form which is checked against a copy of the token held in the user&#039;s session.  By checking that the submitted token matches the one contained in the stored session, it is possible to tie a rendered form to the request variables presented.&lt;br /&gt;
&lt;br /&gt;
In POST forms you should add a hidden token field using:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo JHTML::_( &#039;form.token&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This outputs the token as a hidden form field looking like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;8cb24ae69ffd7828ccecbcf06056e6fc&amp;quot; value=&amp;quot;1&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and places a copy of the token into the user&#039;s session, for later checking.&lt;br /&gt;
&lt;br /&gt;
If you need to add the token to a URL rather than a form then you can use something like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo JRoute::_( &#039;index.php?option=com_mycomponent&amp;amp;&#039; . JSession::getFormToken() . &#039;=1&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the most common scenario, you will want to check the token following a POST to the form handler.  This can be done by adding this line of code to form handler:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JSession::checkToken() or die( JText::_( &#039;Invalid Token&#039; ) );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to pass the token in a GET request then you can check it like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JSession::checkToken( &#039;get&#039; ) or die( JText::_( &#039;Invalid Token&#039; ) );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In both cases the code will die if the token is omitted from the request, or the submitted token does not match the session token.  If the token is correct but has expired, then [[JSession/checkToken|JSession::checkToken]] will automatically redirect to the site front page.&lt;br /&gt;
&lt;br /&gt;
==Cleaning filesystem paths==&lt;br /&gt;
If there is any possibility that a filesystem path might be constructed using data that originated from user input, then the path must be cleaned and checked before being used.  This can be done quite simply like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JPath::check( $path );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This will raise an error and terminate Joomla if the path contains a &amp;quot;..&amp;quot; or leads to a location outside the Joomla root directory.  If you want to deal with the error yourself without terminating the application, then you can use code like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$path = JPath::clean( $path );&lt;br /&gt;
if (strpos( $path, JPath::clean( JPATH_ROOT ) ) !== 0) {&lt;br /&gt;
    // Handle the error here.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The [[JPath:clean]] method can be used in your own code too.  It merely removes leading and trailing whitespace and replace double slashes and backslashes with the standard directory separator.&lt;br /&gt;
&lt;br /&gt;
==Cleaning filesystem file names==&lt;br /&gt;
As with filesystem paths, if there is any possibility that a file name might be constructed using user-originated data, then the file name must be cleaned and checked before use.  This can be done like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
jimport(&#039;joomla.filesystem.file&#039;);&lt;br /&gt;
$clean = JFile::makeSafe( $unclean );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This method removes sequences of two or more &amp;quot;.&amp;quot; characters and any character that is not alphabetic, numeric or a dot, dash or underscore character.  If there is a leading dot then that is removed too.&lt;br /&gt;
[[Category:Development]][[Category:Security]]&lt;/div&gt;</summary>
		<author><name>Mickmackusa</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Pizza_Bugs_and_Fun_2019/Contributors_List&amp;diff=635043</id>
		<title>Pizza Bugs and Fun 2019/Contributors List</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Pizza_Bugs_and_Fun_2019/Contributors_List&amp;diff=635043"/>
		<updated>2019-10-19T01:39:50Z</updated>

		<summary type="html">&lt;p&gt;Mickmackusa: /* Pizza Bugs and Fun 2019/Contributors List */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Pizza Bugs and Fun 2019/Contributors List==&lt;br /&gt;
* Stuart Robertson - Brisbane, Australia&lt;br /&gt;
* Scott Cole - Brisbane, Australia&lt;br /&gt;
* Jerry Bongard - Brisbane, Australia&lt;br /&gt;
* Britt Ambrose - Brisbane, Australia&lt;br /&gt;
* Michael Olumide - Brisbane, Australia&lt;br /&gt;
* Mick Harner - Brisbane, Australia&lt;/div&gt;</summary>
		<author><name>Mickmackusa</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Secure_coding_guidelines&amp;diff=635042</id>
		<title>Secure coding guidelines</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Secure_coding_guidelines&amp;diff=635042"/>
		<updated>2019-10-19T01:37:02Z</updated>

		<summary type="html">&lt;p&gt;Mickmackusa: /* Secure field names */  Fixed syntax error, property arrow was incorrect&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Joomla includes many features that help with the task of securing applications and extensions built on it.  You should always use these features if at all possible as they have been tried and tested by the many eyes of the developer community and any updates that might conceivably be required in the future will be automatically available whenever a Joomla update is applied.  What follows is a description of best practice in using the Joomla API to ensure that your extensions are as secure as possible.&lt;br /&gt;
&lt;br /&gt;
==Getting data from the request==&lt;br /&gt;
{{JVer|3.x}} Starting with Joomla version 3.0, [[Retrieving_request_data_using_JInput|JInput]] should be used instead of [[JRequest]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
All input originating from a user must be considered potentially dangerous and must be cleaned before being used.  You should always use the Joomla [[Retrieving_request_data_using_JInput|JInput]] class to retrieve data from the request, rather than the raw $_GET, $_POST or $_REQUEST variables as the [[Retrieving_request_data_using_JInput|JInput]] methods apply input filtering by default. JInput deals with all aspects of the user request in a way that is independent of the request method used.  It can also be used to retrieve cookie data and even server and environment variables. However, it is important to use the correct [[Retrieving_request_data_using_JInput|JInput]] method to ensure maximum security.  It is very easy to just use the [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]] method with default parameters and ignore the fact that in many cases it is possible to apply a more stringent requirement on user input.&lt;br /&gt;
&lt;br /&gt;
It very important to understand that the [[Retrieving_request_data_using_JInput|JInput]] methods are not SQL-aware and further work is required to guard against SQL injection attacks.There is no default value that will be returned if no default is specified in the call the [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]]. If no default is specified and the argument is not present in the request variable then it will return undefined.&lt;br /&gt;
&lt;br /&gt;
Using [[Retrieving_request_data_using_JInput|JInput]] also obviates the need to pay attention to the setting of magic_quotes_gpc. [[Retrieving_request_data_using_JInput|JInput]] does the right thing, regardless of whether magic_quotes_gpc is on or off.  See http://php.net/manual/en/security.magicquotes.php for further information.&lt;br /&gt;
&lt;br /&gt;
When considering user input you should think about the data type you are expecting to retrieve and apply the most stringent form of [[Retrieving_request_data_using_JInput#Getting_Values|JInput]] that is applicable in each case.  In particular, avoid the lazy approach of using [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]] as this will return an array that may contain entries that you did not expect and although each of those entries will have been cleaned, it is often the case that additional filtering could have been applied to some individual arguments.  For example, the get method treats all arguments as strings, whereas it may be possible to restrict some arguments to be integers.&lt;br /&gt;
&lt;br /&gt;
The first three parameters of each of the JInput get methods are the same.  Only the first parameter is mandatory.  In general, the format is&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
    JFactory::getApplication-&amp;gt;input-&amp;gt;&amp;lt;data-source&amp;gt;-&amp;gt;get&amp;lt;type&amp;gt;( &amp;lt;name&amp;gt;, &amp;lt;default&amp;gt; )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| &amp;lt;type&amp;gt; || the data type to be retrieved (see below for the types available).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;name&amp;gt; || the name of the variable to be retrieved (for example, the name of an argument in a URL).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;default&amp;gt; || the default value.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;amp;lt;data-source&amp;amp;gt; || specifies where the variable is to be retrieved from (see below).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following values for &amp;amp;lt;data-source&amp;amp;gt; are supported:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| get || Data submitted in the query part of the URL.&lt;br /&gt;
|-&lt;br /&gt;
| post || Data submitted from form fields.&lt;br /&gt;
|-&lt;br /&gt;
| method || The same as either GET or POST depending on how the request was made.&lt;br /&gt;
|-&lt;br /&gt;
| cookie || Data submitted in cookies.&lt;br /&gt;
|-&lt;br /&gt;
| request || All the GET, POST and COOKIE data combined.  This is the default.&lt;br /&gt;
|-&lt;br /&gt;
| files || Information about files uploaded as part of a POST request.&lt;br /&gt;
|-&lt;br /&gt;
| env || Environment variables (platform-specific).&lt;br /&gt;
|-&lt;br /&gt;
| server || Web server variables (platform-specific).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Notice that the default is REQUEST, which includes cookie data.&lt;br /&gt;
&lt;br /&gt;
The following sections look at each of the data types in more detail.&lt;br /&gt;
&lt;br /&gt;
===Integer===&lt;br /&gt;
The following will accept an integer.  An integer can include a leading minus sign, but a plus sign is not permitted.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$integer = JFactory::getApplication-&amp;gt;input-&amp;gt;getInt( &#039;id&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return the value of the &amp;quot;id&amp;quot; argument from the request (which by default includes all GET, POST and COOKIE data).  The default value is zero.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$integer = JFactory::getApplication-&amp;gt;input-&amp;gt;cookie-&amp;gt;getInt( &#039;myId&#039;, 12 );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return the value of the &amp;quot;myId&amp;quot; variable from a cookie, with a default value of 12.&lt;br /&gt;
&lt;br /&gt;
===Floating point number===&lt;br /&gt;
A floating point number can include a leading minus sign, but not a plus sign.  If the number includes a decimal point, then there must be at least one digit before the decimal point.  For example,&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$float = JFactory::getApplication-&amp;gt;input-&amp;gt;getFloat( &#039;price&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return the value of the &#039;price&#039; argument from the request.  The default is &amp;quot;0.0&amp;quot;.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$float = JFactory::getApplication-&amp;gt;input-&amp;gt;post-&amp;gt;getFloat( &#039;total&#039;, 100.00 );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &#039;total&#039; argument from a POST request (but not a GET), with a default value of 100.00.&lt;br /&gt;
&lt;br /&gt;
===Boolean value===&lt;br /&gt;
Any non-zero value is regarded as being true; zero is false.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$boolean = JFactory::getApplication-&amp;gt;input-&amp;gt;getBool( &#039;show&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return false if the value of the &#039;show&#039; argument in the request is zero, or 1 (true) if the argument is anything else.  The default is false.  Note that any string argument will result in a return value of true, so calling the above with a URL containing &amp;quot;?show=false&amp;quot; will actually return true!&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$boolean = JFactory::getApplication-&amp;gt;input-&amp;gt;get-&amp;gt;getBool( &#039;hide&#039;, true );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &#039;hide&#039; argument from a GET request (but not a POST), with a default value of true.&lt;br /&gt;
&lt;br /&gt;
===Word===&lt;br /&gt;
A word is defined as being a string of alphabetic characters.  The underscore character is permitted as part of a word.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$word = JFactory::getApplication-&amp;gt;input-&amp;gt;cookie-&amp;gt;getWord( &#039;search-word&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &#039;search-word&#039; argument from the request.  The default is an empty string.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$word = JFactory::getApplication-&amp;gt;input-&amp;gt;cookie-&amp;gt;getWord( &#039;keyword&#039;, &#039;&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &#039;keyword&#039; variable from a cookie, with the default being an empty string.&lt;br /&gt;
&lt;br /&gt;
===Command===&lt;br /&gt;
A command is like a word but a wider range of characters is permitted.  Allowed characters are: all alphanumeric characters, dot, dash (hyphen) and underscore.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$command = JFactory::getApplication-&amp;gt;input-&amp;gt;getCmd( &#039;option&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;option&amp;quot; argument from the request.  The default value is an empty string.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$command = JFactory::getApplication-&amp;gt;input-&amp;gt;post-&amp;gt;getCmd( &#039;controller&#039;, &#039;view&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;controller&amp;quot; argument from a POST request (but not a GET), with a default value of &#039;view&#039;.&lt;br /&gt;
&lt;br /&gt;
===String===&lt;br /&gt;
The string type allows a much wider range of input characters.  It also takes an optional fourth argument specifying some additional mask options.  See [[#Filter options]] for information on the available masks.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$string = JFactory::getApplication-&amp;gt;input-&amp;gt;getString( &#039;description&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;description&amp;quot; argument from the request.  The default value is an empty string.  The input will have whitespace removed from the left and right ends and any HTML tags will be removed.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$string = JFactory::getApplication-&amp;gt;input-&amp;gt;getString( &#039;text&#039;, &#039;&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;text&amp;quot; argument from the request..  The default value is an empty string.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$string = JFactory::getApplication-&amp;gt;input-&amp;gt;getString( &#039;template&#039;, &#039;&amp;lt;html /&amp;gt;&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;template&amp;quot; argument from the request.  The default value is &#039;&amp;lt;html /&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
===JSON String===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$json = JFactory::getApplication-&amp;gt;input-&amp;gt;json-&amp;gt;get( &#039;var_name&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Generic and other data types===&lt;br /&gt;
If the above methods do not meet your needs, there is a small number of additional filter types which you can use by calling the [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]] method directly.  The syntax is:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getApplication-&amp;gt;input-&amp;gt;get( &amp;lt;name&amp;gt;, &amp;lt;default&amp;gt;, &amp;lt;type&amp;gt; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| &amp;lt;name&amp;gt; || the name of the variable to be retrieved (for example, the name of an argument in a URL).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;default&amp;gt; || the default value.  There is no default value that will be returned if no default is specified in the call the [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]].   If no default is specified and the argument is not present in the request variable then it will return undefined.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;type&amp;gt; || specifies the data type expected (see below).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first three arguments are the same as for the more specific methods described earlier.  Only the first argument is mandatory.&lt;br /&gt;
&lt;br /&gt;
Allowed values of the &amp;lt;type&amp;gt;, which is case-insensitive, are as follows:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| INT, INTEGER || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getInt]].&lt;br /&gt;
|-&lt;br /&gt;
| UINT || Get an unsigned integer. Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getUint]].&lt;br /&gt;
|-&lt;br /&gt;
| FLOAT, DOUBLE || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getFloat]].&lt;br /&gt;
|-&lt;br /&gt;
| BOOL, BOOLEAN || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getBool]].&lt;br /&gt;
|-&lt;br /&gt;
| WORD || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getWord]].&lt;br /&gt;
|-&lt;br /&gt;
| ALNUM || Allow only alphanumeric characters (a-z, A-Z, 0-9). Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getAlnum]].&lt;br /&gt;
|-&lt;br /&gt;
| CMD || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getCmd]].&lt;br /&gt;
|-&lt;br /&gt;
| BASE64 || Allow only those characters that could be present in a base64-encoded string (ie. a-z, A-Z, 0-9, /, + and =). Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getBase64]].&lt;br /&gt;
|-&lt;br /&gt;
| STRING || Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getString]].&lt;br /&gt;
|-&lt;br /&gt;
| ARRAY || Source is not filtered but is cast to array type.&lt;br /&gt;
|-&lt;br /&gt;
| HTML || A sanitised string. Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getHtml]].&lt;br /&gt;
|-&lt;br /&gt;
| PATH || Valid pathname regex that filters out common attacks.  For example, any path beginning with a &amp;quot;/&amp;quot; will return an empty string.  Simliarly, any path containing &amp;quot;/./&amp;quot; or &amp;quot;/../&amp;quot; will return an empty string.  Dots within filenames are okay though. Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getPath]].&lt;br /&gt;
|-&lt;br /&gt;
| USERNAME || Removes control characters (0x00 - 0x1F), 0x7F, &amp;lt;, &amp;gt;, &amp;quot;, &#039;, % and &amp;amp;. Equivalent to [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;getUsername]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Filter options===&lt;br /&gt;
All input values can be filtered using JFilterInput-&amp;gt;clean.&lt;br /&gt;
&lt;br /&gt;
Filter an array of values.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$data = JFactory::getApplication()-&amp;gt;input-&amp;gt;post-&amp;gt;get(&#039;data&#039;, array(), &#039;array&#039;);&lt;br /&gt;
$filter = JFilterInput::getInstance();&lt;br /&gt;
&lt;br /&gt;
foreach ($data as $value)&lt;br /&gt;
{&lt;br /&gt;
	$array[] = $filter-&amp;gt;clean($value, &#039;string&#039;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
For more filter types see [https://github.com/joomla/joomla-cms/blob/master/libraries/joomla/filter/input.php#L115 JFilterInput source].&lt;br /&gt;
&lt;br /&gt;
Options listed bellow available only in deprecated [[JRequest]] library.&lt;br /&gt;
Allowed values of &amp;lt;options&amp;gt; are as follows (none of these are applied by default):&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| JREQUEST_NOTRIM || Does not remove whitespace from the start and ends of strings.&lt;br /&gt;
|-&lt;br /&gt;
| JREQUEST_ALLOWRAW || Does not do any filtering at all.  Use with extreme caution.&lt;br /&gt;
|-&lt;br /&gt;
| JREQUEST_ALLOWHTML || Does not remove HTML from string inputs.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Masks can be combined by logically OR&#039;ing them.  If no filter options are specified, then by default, whitespace is trimmed and HTML is removed.&lt;br /&gt;
&lt;br /&gt;
===File uploads===&lt;br /&gt;
Web servers already have a good deal of security around handling file uploads, but it is still necessary to take additional steps to ensure that file names and paths cannot be abused.  A simplified form which requests a file to be uploaded looks like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;index.php?option=com_mycomponent/form_handler.php&amp;quot;  method=&amp;quot;post&amp;quot; enctype=&amp;quot;multipart/form-data&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;input type=&amp;quot;file&amp;quot; name=&amp;quot;Filedata&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;input type=&amp;quot;submit&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
On clicking the submit button, the browser will upload the file in a POST request, passing control to Joomla which will call &amp;quot;components/com_mycomponent/form_handler.php&amp;quot;.  This will include code like the following.  The variable $somepath must be set to some path where the web server has permission to create files.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;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;
// Get the file data array from the request.&lt;br /&gt;
$file = JFactory::getApplication-&amp;gt;input-&amp;gt;get( &#039;Filedata&#039;, &#039;&#039;, &#039;files&#039;, &#039;array&#039; );&lt;br /&gt;
&lt;br /&gt;
// Make the file name safe.&lt;br /&gt;
jimport(&#039;joomla.filesystem.file&#039;);&lt;br /&gt;
$file[&#039;name&#039;] = JFile::makeSafe($file[&#039;name&#039;]);&lt;br /&gt;
&lt;br /&gt;
// Move the uploaded file into a permanent location.&lt;br /&gt;
if (isset( $file[&#039;name&#039;] )) {&lt;br /&gt;
&lt;br /&gt;
    // Make sure that the full file path is safe.&lt;br /&gt;
    $filepath = JPath::clean( $somepath.&#039;/&#039;.strtolower( $file[&#039;name&#039;] ) );&lt;br /&gt;
&lt;br /&gt;
    // Move the uploaded file.&lt;br /&gt;
    JFile::upload( $file[&#039;tmp_name&#039;], $filepath );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Saving a request variable into user state===&lt;br /&gt;
Because setting a user state variable from a variable in the request is such a common operation, there is an API method to make the task easier.  This is generally safe to use because it calls [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]] to obtain the input from the request, but remember that none of the input filtering calls will protect against SQL injection attempts.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$app = JFactory::getApplication();&lt;br /&gt;
$app-&amp;gt;getUserStateFromRequest( &amp;lt;key&amp;gt;, &amp;lt;name&amp;gt;, &amp;lt;default&amp;gt;, &amp;lt;type&amp;gt; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
where&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| &amp;lt;key&amp;gt; || the name of the variable in the user state.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;name&amp;gt; || the name of the request variable (same as the first argument of a [[Retrieving_request_data_using_JInput#Getting_Values|JInput-&amp;gt;get]] call).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;default&amp;gt; || the default value to be assigned to the user state variable if the request variable is absent.  The default is null.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;type&amp;gt; || the type of variable expected.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, getting an integer variable called &#039;id&#039; from the request with a default value of 0, then saving it into a session variable called &#039;myid&#039; can be done like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$app = JFactory::getApplication();&lt;br /&gt;
$app-&amp;gt;getUserStateFromRequest( &#039;myid&#039;, &#039;id, 0, &#039;int&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
instead of something like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$app = JFactory::getApplication();&lt;br /&gt;
$app-&amp;gt;setUserState( &#039;myid&#039;, $app-&amp;gt;input-&amp;gt;getInt( &#039;id&#039;, 0 ) );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Constructing SQL queries==&lt;br /&gt;
One of the most common forms of attack on web applications is SQL injection, where the aim of the attacker is to change a database query by exploiting a poorly filtered input variable.  Injecting modified SQL statements into the database can damage data or reveal private information.  It is important to ensure that when SQL statements are constructed, they are correctly escaped and quoted so that bad input data cannot result in a bad SQL statement. You cannot rely on the [[Retrieving_request_data_using_JInput|JInput]] methods to do this as they are not SQL-aware.&lt;br /&gt;
&lt;br /&gt;
===Secure integers and the rest of numeric values===&lt;br /&gt;
With the MySQL database, numeric fields should not be quoted, so it is important that they be typecast instead.  Failure to do this will leave your code vulnerable to an attacker inserting a string containing SQL data.&lt;br /&gt;
&lt;br /&gt;
Depending on the type, numeric types are cast like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// For SQL data types: INT, INTEGER, TINYINT, SMALLINT, MEDIUMINT, BIGINT, YEAR&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `id`=&#039; . (int) $id;&lt;br /&gt;
&lt;br /&gt;
// For SQL data types: FLOAT, DOUBLE&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `id`=&#039; . (float) $id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
It&#039;s a good idea to get into the habit of always typecasting integers like this even if the variable was previously obtained using JInput-&amp;gt;getInt. Further information on SQL injection attacks can be found here: http://php.net/manual/en/security.database.sql-injection.php and here: [[Retrieving_request_data_using_JInput#Getting_Values]].&lt;br /&gt;
&lt;br /&gt;
===Secure strings===&lt;br /&gt;
In the examples that follow it is assumed that $db is an instance of a Joomla database object.  This can always be obtained from [[JFactory]] using&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDBO();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Strings should always be escaped before being used in an SQL statement.  This is actually very simple as the [[JDatabase/quote|JDatabase-&amp;gt;quote]] method escapes everything for you.  You can also use the [[JDatabase/escape|JDatabase-&amp;gt;escape]] method directly.  The following statements are equivalent:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `field` = &#039; . $db-&amp;gt;quote( $db-&amp;gt;escape( $field ), false );&lt;br /&gt;
&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `field` = &#039; . $db-&amp;gt;quote( $field );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
===Secure on search===&lt;br /&gt;
Special attention should be paid to LIKE clauses which contain the % wildcard character as these require special escaping in order to avoid possible denial of service attacks.  LIKE clauses can be handled like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Construct the search term by escaping the user-supplied string and, if required, adding the % wildcard characters manually.&lt;br /&gt;
$search = &#039;%&#039; . $db-&amp;gt;escape( $search, true ) . &#039;%&#039;;&lt;br /&gt;
&lt;br /&gt;
// Construct the SQL query, being careful to suppress the default behaviour of Quote so as to prevent double-escaping.&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `field` LIKE &#039; . $db-&amp;gt;quote( $search, false );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Secure dates===&lt;br /&gt;
If data is to be entered into a datetime column then you can use the Joomla API to ensure a valid date format:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$date = JFactory::getDate( $mydate );&lt;br /&gt;
$query = &#039;UPDATE #__table SET `date` = &#039; . $db-&amp;gt;quote( $date-&amp;gt;toMySQL(), false );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Note that it is necessary to suppress database escaping as legitimate dates may contain characters that should not be escaped.&lt;br /&gt;
&lt;br /&gt;
===Secure field names===&lt;br /&gt;
In the comparatively rare case where a field name is a variable, that should also be quoted using an API call:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE &#039; . $db-&amp;gt;quoteName( $field-&amp;gt;name ) . &#039;=&#039; . $db-&amp;gt;quote( $field-&amp;gt;value );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Secure arrays of integers===&lt;br /&gt;
When you have an array of ids, typically used for IN() queries, you have to sanitise it also with JArrayHelper::toInteger($cid); before imploding: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
JArrayHelper::toInteger($catId);&lt;br /&gt;
$query-&amp;gt;where($db-&amp;gt;quoteName(&#039;x.category_id&#039;) . &#039; IN (&#039; . implode(&#039;,&#039;, $catId) . &#039;)&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Short aliases of Quote and QuoteName===&lt;br /&gt;
Shorter alternatives to the quote methods may also be used.  The following statements are equivalent:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE &#039; . $db-&amp;gt;quoteName( $field-name ) . &#039;=&#039; . $db-&amp;gt;quote( $field-value );&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE &#039; . $db-&amp;gt;qn( $field-name ) . &#039;=&#039; . $db-&amp;gt;q( $field-value );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Securing forms==&lt;br /&gt;
Apart from cleaning input variables as described above, you can also implement a simple technique which makes it more difficult for a cross-site request forgery attack (CSRF) to succeed. This involves adding a randomly-generated unique token to the form which is checked against a copy of the token held in the user&#039;s session.  By checking that the submitted token matches the one contained in the stored session, it is possible to tie a rendered form to the request variables presented.&lt;br /&gt;
&lt;br /&gt;
In POST forms you should add a hidden token field using:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo JHTML::_( &#039;form.token&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This outputs the token as a hidden form field looking like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;8cb24ae69ffd7828ccecbcf06056e6fc&amp;quot; value=&amp;quot;1&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and places a copy of the token into the user&#039;s session, for later checking.&lt;br /&gt;
&lt;br /&gt;
If you need to add the token to a URL rather than a form then you can use something like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo JRoute::_( &#039;index.php?option=com_mycomponent&amp;amp;&#039; . JSession::getFormToken() . &#039;=1&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the most common scenario, you will want to check the token following a POST to the form handler.  This can be done by adding this line of code to form handler:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JSession::checkToken() or die( JText::_( &#039;Invalid Token&#039; ) );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to pass the token in a GET request then you can check it like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JSession::checkToken( &#039;get&#039; ) or die( JText::_( &#039;Invalid Token&#039; ) );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In both cases the code will die if the token is omitted from the request, or the submitted token does not match the session token.  If the token is correct but has expired, then [[JSession/checkToken|JSession::checkToken]] will automatically redirect to the site front page.&lt;br /&gt;
&lt;br /&gt;
==Cleaning filesystem paths==&lt;br /&gt;
If there is any possibility that a filesystem path might be constructed using data that originated from user input, then the path must be cleaned and checked before being used.  This can be done quite simply like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JPath::check( $path );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This will raise an error and terminate Joomla if the path contains a &amp;quot;..&amp;quot; or leads to a location outside the Joomla root directory.  If you want to deal with the error yourself without terminating the application, then you can use code like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$path = JPath::clean( $path );&lt;br /&gt;
if (strpos( $path, JPath::clean( JPATH_ROOT ) ) !== 0) {&lt;br /&gt;
    // Handle the error here.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The [[JPath:clean]] method can be used in your own code too.  It merely removes leading and trailing whitespace and replace double slashes and backslashes with the standard directory separator.&lt;br /&gt;
&lt;br /&gt;
==Cleaning filesystem file names==&lt;br /&gt;
As with filesystem paths, if there is any possibility that a file name might be constructed using user-originated data, then the file name must be cleaned and checked before use.  This can be done like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
jimport(&#039;joomla.filesystem.file&#039;);&lt;br /&gt;
$clean = JFile::makeSafe( $unclean );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This method removes sequences of two or more &amp;quot;.&amp;quot; characters and any character that is not alphabetic, numeric or a dot, dash or underscore character.  If there is a leading dot then that is removed too.&lt;br /&gt;
[[Category:Development]][[Category:Security]]&lt;/div&gt;</summary>
		<author><name>Mickmackusa</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=User:Mickmackusa&amp;diff=635022</id>
		<title>User:Mickmackusa</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=User:Mickmackusa&amp;diff=635022"/>
		<updated>2019-10-19T00:45:50Z</updated>

		<summary type="html">&lt;p&gt;Mickmackusa: my new user page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;My name is Mickmackusa 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>Mickmackusa</name></author>
	</entry>
</feed>