Loop through recordset

Loop through recordset

Select rows from a Joomla database table and loop through the results in PHP with loadObjectList. A short example with select, where and order.

How to select and loop through a recordset is shown below. Wtith a results, and a loop option:

$jn_select="*"; $jn_from="from_table"; $jn_where="state = 1"; $jn_orderby="id asc";
$db = Factory::getDBO(); $query = $db->getQuery(true) -> select($jn_select) -> from($db->quoteName($jn_from)) -> where($jn_where) -> order ($jn_orderby); if ($jn_setlimit){ $query->setLimit($jn_setlimit); // max can be set } $db->setQuery($query); $results = $db->loadObjectList();   foreach ($results as $item) { echo $item->column_name }   Happy coding!
Stuck on something else?

Doctor Joomla is a project of Cloudfaction, a Dutch agency building and maintaining Joomla sites since 1999. The articles are made with the help of AI, so tell us if something does not match your screen. Mail info@cloudfaction.nl if you want someone to look at yours.

Rather have someone look at it

Doctor Joomla is a Cloudfaction project.

A Dutch agency that has been building and running Joomla sites since 1999. If your site needs more than an article can fix, get in touch.