Auto Generate Pages Using PHP

Is there a way to auto generate thousands of pages using PHP. I want to create a series of pages that can be used for natural search efforts. I know there's a way to link to the same page and pass a query string and use that to update some information in the page, but I was wondering if there would any advantage to creating thousands of pages instead. Then the search engines would see them as separate pages.
Here's what I want to do. If I had a list of all 50 states with a list of all of the cities in those states, could I use PHP to generate a separate page for every one of those cities? Would I just throw all of the city and state names into a database and then use PHP to generate pages based on those database values? Would that be an advance PHP technique? Also, would the search engines punish me for that?
Thanks,
James

Re: Auto Generate Pages Using PHP
Rather than generate thousands of pages, it's best to use a single page and use Apache's built-in ModRewrite feature.
WARNING - This is an advanced feature that requires careful implementation.
Check out AudioBookHub.com to see how I implemented this -
http://www.audiobookhub.com/author-detail/a_lady_of_distinction/
http://www.audiobookhub.com/author-detail/a._roger_merrill_and_rebecca_r._merrill/
http://www.audiobookhub.com/author-detail/a.a._milne/
Even those these pages have distinct URLs and are viewed as separate pages by the SERPs, they're all generated from one PHP script (author-detail.php).
For more advice on this check out Jamie Sirovich's book - Search Engine Optimization with PHP:
http://www.seoegghead.com/