That aint hard... in the database, store a link together with the banner id, and simply output the link, along with the id to the HTML HREF tag
printf ("<a href=http://%s><img src=banner.php?bannerid=%s&somerandomnumber=1234></a>",$result[b_link],$result[b_id]);
//the random number is there to prevent image caching 🙂)