Before you start using PHP in conjunction with MySQL, it would be hugely beneficial to read the manual.
MySQL Docs &
PHP Docs - You'll find yourself constantly heading back to these sources of documentation. However, those manuals are just basic documentation.
A couple of tutorials explaining the basics of MySQL & PHP would come in handy here, so I suggest heading over to the Zend website (they created PHP) and follow:
Rotating Banner Advertisements with PHP and, [url=http://www.zend.com/zend/tut/tutorial-yank.php][b]Build your own database driven website using PHP & MySQL. Alternatively, check out
Zend's Tutorial Page for a whole heap of PHP tutorials, not all MySQL related.