I need to transform a simple php query into a query that JDATABASE
will understand.
Here is the example:
$resDays = 7; // On how many days to build the top?
$resLimit = 20; // How many results to display?
$query = "SELECT `artist`, title, count(*) AS tracks FROM `history
WHERE TIMESTAMPDIFF(DAY, `date_played`, NOW()) <= " . $resDays . "
AND `song_type`=0 GROUP BY title ORDER BY tracks DESC LIMIT 0," . $resLimit;
And this is what I managed to do:
// Create a new query object.
$query = $db->getQuery(true);
$query->select($db->quoteName(array('artist', 'title')));
$query->from($db->quoteName('history'));
$db->setQuery($query);
$query->setLimit(20);
$result = $db->loadObjectList();
The problem is that I don't know how to include in my query the missing parts like ORDER tracks
or count(*) AS tracks
.