<?
$fh1 = fopen("c:/users.txt", 'r'); //the 'r' argument specifies that the file will be opened for read only
$fh2= fopen("c:/users2.txt", 'r');
//parse the first file
while ($var1[] = fgetcsv($fh1,1024,"\t")) //assume this is the lookup file
{
// bad coding but dont need to do anything
}
//now have an array or arrays which need cleaning up
foreach ($var1 as $key=>$val)
{
$customerdata[$val[0]]=array("customername"=>$val[1],"addressline1"=>$val[2],"addressline2"=>$val[2]);
}
unset($var1);
//parse the second file
while ($var2[] = fgetcsv($fh2,1024,"\t")) //assume this is the lookup file
{
// ditto
}
//transform $var2 into an easy lookup
foreach ($var2 as $key => $val)
{
$customerdata[$val[0]]["somedata1"] = $val[1]; //this takes the second col and assigns it to the earlier variable with the ssame key as in the first col.
}
unset ($var2); //destroy the variable to free memory
//close the csv files
fclose($fh1);
fclose($fh2);
//assuming this is a standard vlookup with a single input column
// you can now lookup each item in the first file and find its corresponding value using something like this:
//you could also choose just to read the first file now and perform the lookup on the incoming data
echo "<table border=\"1\">";
echo "<tr>";
echo "<td>CustomerID</td>";
echo "<td>customer name</td>";
echo "<td>address line 1</td>";
echo "<td>address line 2</td>";
echo "<td>some data 1</td>";
echo"</tr>";
foreach ($customerdata as $key=>$val)
{
extract($val);
echo "<tr>";
echo "<td>$key</td>";
echo "<td>$customername</td>";
echo "<td>$addressline1</td>";
echo "<td>$addressline2</td>";
echo "<td>$somedata1</td>";
echo"</tr>";
}
echo "<table>";
?>