I am reading a datafile which is :separated it looks abit like this
City County Latitude Longitude Easting Northing
NEWLYN CL -19980 -19980 146 28
NEWMALDEN LD -960 -960 520 168
NEWMARKET SF 1440 1440 563 262
NEWMILLS DY -7200 -7200 400 385
NEWMILNS SH -15600 -15600 253 636
NEWMILTON HE -5940 -5940 424 94
NEWNHAM GR -8820 -8820 368 211
NEWPORT EX 780 780 552 234
NEWPORT GW -10800 -10800 330 187
NEWPORT IW -4680 -4680 449 89
NEWPORT PK -17400 -17400 205 239
NEWPORT SE -8519 -8519 375 318
the problem i have is if the user enters a town the find the first town that matchs but if the user enters a town and county as well then should try to find the match the problem is that it always stops at the first match eg NEWPOERT and not NEWPORT IW
[ code ]
/ open the data file /
$fn = fopen("/townsx","r");
/ now to read the files record by record /
while($rec = fgets($fn,256))
{
/ split each record into fields (: is separator) /
$elem = split(":",$rec);
if($elem[0] == $town1 && $elem[1] == $county1)
{
$g1 = 1;
$x1 = $elem[4];
$y1 = $elem[5];
}
else if($elem[0] == $town1)
{
$g1 = 1;
$x1 = $elem[4];
$y1 = $elem[5];
}
if($elem[0] == $town2 && $elem[1] == $county2)
{
$g2 = 1;
$x2 = $elem[4];
$y2 = $elem[5];
}
else if($elem[0] == $town2)
{
$g2 = 1;
$x2 = $elem[4];
$y2 = $elem[5];
}
/ test whether towns have been found /
if( $g1 == 1 && $g2 == 1 && $g3 == 1) break;
[ code ]