I would recomend the following. [code] $link =mysql_connect($hostname,$username, $password) OR DIE ("Unable to connect to database! Please try again later."); mysql_select_db($dbname); $arr_b = array("x500y500","x510y500"); $arr_r = array("x500y510","x500y520","x510y510","x510y520"); foreach($arr_b as $coord){ $res = mysql_query("select ct.*, cr.* from coordsTaken ct, coordsReserved cr where cr.xyPOS=ct.xyPOS and ct.xyPOS='$coord'"); if(!$res || !mysql_num_rows($res)){ echo "Bad Coordinate"; }else echo "Good Coordinate"; } foreach($arr_r as $coord){ $res = mysql_query("select ct.*, cr.* from coordsTaken ct, coordsReserved cr where cr.xyPOS=ct.xyPOS and ct.xyPOS='$coord'"); if(!$res || !mysql_num_rows($res)){ echo "Bad Coordinate"; }else echo "Good Coordinate"; } mysql_close($link); [/code] Combining the queries will save on the query count and is much faster. The more you can do in a query, the better. It's much more efficient to have the DB do the work then the code. foreach loops are also much faster than for loops. The way you structured the for loop is also inefficient. [code] for ($i=0; $i < count($arr_b); $i++){ [/code] he problem with this is that after every iteration, count($arr_b) will be re-evaluated. So if the array is very large, you will be re-evaluating a constant value needlessly (unless the size of the array is modified in the loop). Much more efficient to do something such as; [code] $size = count($arr_b); for ($i=0; $i < $size; $i++){ [/code] That way count($arr_b) is only evaluated once. With small arrays this isn't an issue, but if the array is large, it can add processing time.