Convert url strings to formatted urls

Hello,

I have a site where I am querying a custom database based on a url string.

For example: http://www.mysite.com/candy/?candyid=1234

would query the database and return the candy type based on the candyid.

I’d like to “Pretty up” the url so that I can include the description of the candy along with the candyid and .html for SEO purposes:

For example: http://www.mysite.com/candy/delicious-black-licorice-from-holland-1234.html

Please note that the “candy” page is a physical page created in WordPress with a custom template to query the database and display the output.

Any direction is appreciated.

Thanks!