SQL:
This is just a simple join.
SELECT e.Votes, e.Views, e.id, u.username
FROM election as e, userinfo as u
WHERE e.ElectionId = u.id WHERE e.ElectionId=?
ORDER BY e.id ASC
Now you can iterate over all lines and every time e.id is changing you know that you have to display a new group.
PHP:
- usually classes are starting with a capital letter.
- usually method are starting with a lower case letter.
- there is something missing in your output, some
echo
s?