Actions

JDatabase/loadAssocList

From Joomla! Documentation

Revision as of 09:32, 3 August 2010 by Nonos (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The method loadAssocList is like an array of the loadAssoc for each row of the table.

Let's use "staalanden" table that was created on his tutorial Developing a Model-View-Controller Component - Part 3 - Using the Database[1]

Fields were "ID" and "greeting", let's do a query like "select * from #__hello"

$data=$db->loadAssocList();

print_r($data);

Results :

Array([0]=>Array([ID]=>1,[greeting]=>Hello, World!),[1]=>Array([ID]=>2,[greeting]=>Bonjour, Monde!),[2]=>Array([ID]=>3,[greeting]=>Ciao, Mondo!))

The method can get a parameter which must be a field name of the result query, it will change the array index into the field name of the row.