Есть такой кусок кода:
$result1 = mysql_query("SELECT id,a,b FROM $table1");
while ($row1 = mysql_fetch_array($result1))
{
$coord1 = mysql_query("SELECT lat,lng FROM $table2 where id in (select first_id from $table1 where link_id=2)");
$row2 = mysql_fetch_array($coord1);
echo "Номер ".$row1['id'].": ";
};