**api/index.php** need 'group by e.id' at the end of the sql string, while it has 'count(r.id)' in select part.