I am sure there are many people on this forum willing to help you. However, there are a few things wrong with your post that minimize your chances on an answer:
Script. Maybe you do, but I don't see the connection.
Secondly, you post a lot of code without any indication of problematic lines or something like that.
But finally, and that makes it impossible to answer this, you don't tell us what the problem is. You don't describe the problem, errors or general expected behavior of the page at all. You don't expect us to get this code, save it somewhere, try to recreate your scenario, create a new database based on the SELECT statements in the code and then try to figure out the problem, do you???
I suggest you read How To Ask Questions The Smart Way
. I am sure you'll find it an enlighting article to read. Then come back to p2p.wrox.com, select the proper forum, and ask a question the smart way.
Everyone is unique, except for me.
While typing this post, I was listening to: Avon
by Queens of the Stone Age
(Track 2 from the album: Queens of the Stone Age
) What's This?