I take a number of rows from the MySQL table:
$IDs = array(5,3,1,4,2); $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select($db->quoteName(array('id','introtext'))) ->from($db->quoteName('#__content')) ->where($db->quoteName('id')." IN (".implode(',', $IDs).")"); $db->setQuery($query); $articles = $db->loadObjectList(); And I bring it on the site through:
foreach($articles as $article) { echo $article->introtext; } But everything is displayed NOT according to the order of the $ IDs array, i.e. First the object with ID 5, then 3, etc. but in ascending order i.e. 1, 2, 3, 4, 5.
How to make everything output according to the $ IDs array?
ps. Joomla API Syntax
ORDER BY FIELD(id, " . implode(',', $IDs) . ")(I donβt know how it will be correct in PHP and Joomla), but it is quite possible (to check) which is better in terms of performance will sort in the php code. - Regent$IDsand take the correspondingarticlefrom the hash table. - Regent