if ryancys query gives you the error try this ( just added alias "b" for the tblcountrydistributor table)
$sql2="select a.* from tbldistributor a inner join tblcountrydistributor b on b.distributorid=a.id where b.countryid=".$countryid." and b.distributorid between ".$p." and 1 ";