Many PHP programmers who I have come across are unsure on how to optimize their MySQL queries.
I'm just going to provide a few tips on how to eliminate most causes of slow queries (on basic queries, I will go into more complex queries in another protip)
Always provide exactly what you want to retrieve back from the query, Never just select everything (*)
The reason for this is that if you don't use every bit of information which you are pulling back then it is wasted time and resources on doing this, another reason for doing this is to prevent the DB engine from enumerating the fields itself. It will know exactly what to get from what you have provided.
The next thing is (where applicable) always limit your query results to a small set if you can. As you can see in the following example, you will only ever want one row returned as there should only ever be one user with the ID of 1. This again stops MySQL (in this case) from pulling back more data than needed (this is not the case in the below example as, again, there will only ever been one user with the ID of 1)
SELECT * FROM users WHERE users.id = 1;
SELECT username, password, email, first_name, last_name FROM users WHERE users.id = 1 LIMIT 1;
I will get into the more complex queries, such as Joins and sub queries next protip.