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.