What I am trying to do is this:
I have a warehouse tracking site. People in the warehouse walk around with PDAs and scan VIN numbers. Once they are done, they generate a txt file with all of the scanned VIN numbers. Here is where I come in. When they upload this file I have to loop through the file and check to see if the VIN is currently in our Units table. If not then I need to give them a list to print out of all of these units that are in the system but not in the warehouse.
With that said, what I have right now I am only echoing the results to see what is going on and of course the echo below is in a for loop so I expect to see some entries more than once (this is just for testing). But what is happening is I am only getting one VIN echoing through the entire for loop and that VIN is in both the system and the file. So it should NOT be assigned to my array.
Here is my code :
[code]
$db = db_connect();
//we open our file
$fp = fopen($upfile, “r”);
//now we check to see if the VIN is already in our system. If not, then we
//put it in our array to notify them
//here we grab all of the VINs currently in MUMs to do our check against the file’s contents
$query = “select Serial_VIN from units”;
$result = @mysql_query($query);
//we initialize our counter for our array at 0
$j = 0;
//now we loop through our query results
for ($i = 0; $i < @mysql_num_rows($result); $i++)
{
//we set/reset our $found var that tells us whether or not we have the VIN in both the file and the units table
$found = false;
//we grab a row
$row = @mysql_fetch_array($result);
//now we rewind the file to the beginning so we can start over
rewind($fp);
//now we loop through until we reach the end of our file
while (!feof($fp))
{
//grab a line from our file
$line = trim(fgets($fp,512));
//if we find the Vin in the file, we set $found to true
if ($row[“Serial_VIN”] == $line)
$found = true;
}
//now if we did not find the VIN in our file, we add the VIN to our array for
//later display
if (!$found)
{
$HTTP_SESSION_VARS[“VIN”][$j] = $line;
echo $HTTP_SESSION_VARS[“VIN”][$j].”<br>”;
//increment array counter
$j++;
}
}
//close file
fclose($fp);
//here we delete the file now that we are done.
unlink($upfile);
BTW if you see a less resource taxing way to pull this off, by all means let me know. There could potentially be thousands of records in both the file and the units table. I am not sure my way is the best, because I am looping through the table grabbing a row then looping through my file for each row. I know there has to be an easier way to do this. Maybe the query? Keep in mind I have to know what is in the DB table but not in the file.
Thank you for any help