I am using a textfile that has 76 rows, each row is a region in the UK (not in alphabetical order).
I need to get a list either echoed out to the browser or as a textfile of the postcode for each region.
The script below always gets the same postcode for each region - even when I make the query inside a function that is called every time the loop increments by 1.
<?php
mysql_connect("", "", "");
mysql_select_db("");
$region_file = fopen("regions_left_for_php.txt", "r");
$temp = fread ($region_file, filesize ("regions_left_for_php.txt"));
fclose ($region_file);
$datalines = explode ("\n", $temp);
$postcode_file = "postcodes.txt";
$fh = fopen($postcode_file, 'a');
foreach ($datalines as $region)
{
$i++;
echo $i.": ".$region." = ".region_search($i)."<br>";
//$stringData = $postcode."\n";
//fwrite($fh, $stringData);
//echo $datalines[$i]."<br />";
}
function region_search($i)
{
$region_sql = "SELECT dealer_region, postcode_1 FROM dealers WHERE dealer_region LIKE '$datalines[$i]'";
$region_sql_result = mysql_query($region_sql);
$row = mysql_fetch_array($region_sql_result);
$postcode = $row['postcode_1'];
return $postcode;
}
?>
Cheers