I’m putting this in here because I’ve done it myself and I’ve seen it done by others.
NEVER EVER use mysql_query() in a loop (like while(), for(), foreach() … ). It will slow down your script and drive you nuts. It’s the wrong way of doing anything you have in mind.
Another thing is using union(). If you have one big mysql query and you union the results of that one with some other query, well, that is going to be a hard bone to chew for your web server. Same thing applies to joins. The more joins you will use in your query, the longer the server will take to process it and the more resources will be consumed.
Sometimes, instead of a join is better to use 2 different mysql queries that will give the same result. It’s up to you to decide what the scenario will be. But you must always remember that if an application runs well with 100 rows in the database, that will change when you’ll have 10.000 rows.