How to display content from external db with relevant urls

Have a look at this question for a fairly simple solution.

Basically, create a plugin to contain your code, add a rewrite rule to intercept any requests that match your custom url, and parse or pass whatever data they contain to your plugin, which can then use those variables to produce whatever output you need.

I also suggest using the wpdb class to do your database queries.