A: 

Could it be that you reuse the variable $query or $result further down leading to output the result of the first $query or to execute the same query again?

Thariama
Can I not use the same variable? I tried doing `$query = NULL` and `$result = NULL` and this made no difference...
Neurofluxation
Do you buy your variables, so that you only have limited variables qty ? ;). Try with other variables, just to see if it works.
Clement Herreman
Of course you can use same variables, but it's often a problem that one doesn't assign new value to the variable (by mistake). Now, when you sent us more code, it looks that it's not your case.
Tomasz Struczyński
right, that is what i am talking about. one can reuse variables, but it is a possible source of errors
Thariama
+1  A: 

I'm not sure if this is the cause but...

first SQL:

$query  = "SELECT name, pub, hospital, trade FROM settlements WHERE settlementID = 1";

Second:

$query  = "SELECT name, shop, hospital, trade FROM settlements WHERE settlementID = 2";

in first one there's pub, in second one - shop. But you don't use shop value in PHP in second case, only pub (which is not in this SQL fields.

You may have SQL error here (no field in database) or PHP error (checking non-existent field in result array).

Tomasz Struczyński