Solved the problem. Might some cleanup and/or advise
Security

You should use prepared statements for all variable data to protect against SQL injection.

The thing is, Joomla actually doesn't seem to support prepared statements. For me, that would be a reason to think about using a different CMS, but you should at the very least follow their guidelines to prevent SQL injection (checking data type and escaping. which - when done correctly - does offer complete protection against injections).

When echoing data, you should also protect against XSS.

Misc


all your SQL keywords should be uppercase (eg and -> AND) to increase readability.
your table and column names are too long, which makes the queries hard to read. For example, to you really need customsforall or virtuemart in them? 
you get a new DBO for each query, this doesn't seem necessary.
you should be able to use JOIN to reduce the amount of queries you have.