Comparing Table column data with other acquired data
Posted: Mon Jan 15, 2007 3:21 pm
i wanted to do a brute force check.
i have a script where i get some data from a tab delimited file. the only thing that i'll check is the first part or $data[0]. from there i check to see if that is the same as anything else within the MySQL tables. so i wanted it to cycle though the whole tables' columns and check to see if it's there. if not then it'll add it, otherwise it skips it.
this is the code that i have thus far:
so, any good ideas as how to do this?
ps: nevermind syntaxual errors if you come across them. those are easy to fix. thank you though
i have a script where i get some data from a tab delimited file. the only thing that i'll check is the first part or $data[0]. from there i check to see if that is the same as anything else within the MySQL tables. so i wanted it to cycle though the whole tables' columns and check to see if it's there. if not then it'll add it, otherwise it skips it.
this is the code that i have thus far:
Code: Select all
// set file to read
$FileRead = "token.test.txt";
// open file
$FileReadHandle = fopen ($FileRead, "r") or die("Could not open file");
$i = 0;
$file = null;
while (!feof($FileReadHandle))
{
$data = fgets($FileReadHandle);
$data = explode("\t", $data);
$margin = @(($data[1] - $data[2]) / $data[1]);
// this means that we entered a row in the file that has no data.
// skip it and continue. most likely we are at the end anyways
if ($data[0] == '')
continue;
$qryTxt = "SELECT part FROM prices WHERE part = '$data[0]' ORDER BY part"
$result = mysql_query($qryTxt);
while($row = mysql_fetch_array($result))
{
if ($row['part'] == $data[0])
{
echo 'same: ' . $row['part'] . ' - ' . $data[0] . '<BR>';
}
else
{
mysql_query("INSERT INTO prices (part) VALUES ('$data[0]')");
}
$i++;
}
}
// close file
fclose($FileReadHandle);ps: nevermind syntaxual errors if you come across them. those are easy to fix. thank you though