MySQL is being thrown out the window, window locked and key melted so I strongly suggest you switch to MySQLi or PDO as per the php website .

You really need to break your code down and write English comments as many people will discard your post the minute they see a massive chunk of code. The Database::query method appears to return a resource ID so you can call a mysql_fetch_assoc/array() function to retrieve the next row in the result set - of course you're going to change to MySQLi though and use mysqli_fetch_assoc()

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."

"One of my most productive days was throwing away 1000 lines of code."