freed query result.
changed to HEREDOC notation for SQL query.
rewrote query to use JOINs and table name aliases.
death to array_push().
updated docblock.
Merge pull request #273 from stopfstedt/master

code cleanup.