Posted: Thu Jan 18, 2007 2:38 am
This is easily the most frustrating piece of code I've ever worked on. It's probably a combination of my getting almost no sleep, stress unrelated to php and the fact that I never work with large files, but I could probably kill somebody right now. 
Take a look at the lines I marked... where it says "always echos 1" and "increments"... what is causing this behavior?? am I just really sleepy and missing something?
Take a look at the lines I marked... where it says "always echos 1" and "increments"... what is causing this behavior?? am I just really sleepy and missing something?
Code: Select all
if ($r = mysql_query($query))
{
/**
* Loop through each product
*/
$i = 0;
while ($row = mysql_fetch_assoc($r))
{
$this_row_stock = 0;
$i++;
// Output part number and name
echo "<td>" . htmlentities($row['pItem']) . "</td>\n";
echo "<td>" . htmlentities($row['pName']) . "</td>\n";
/**
* Loop through each file
*/
foreach ($csv_files as $key => $file)
{
if (!isset($filehandles[$key])) $filehandles[$key] = fopen($file['src'], "r");
/**
* Loop through each line
*/
while (($data = fgetcsv($filehandles[$key], 1000, $file['delim'], $file['enc'])) !== FALSE)
{
if (getAlnum($row['pItem']) == $data[$file['sku_position']])
{
echo 'found: ' . $row['pItem'];
}
echo $i . " "; // Always echos 1
}
echo $i . " "; // increments
}
echo '<td>' . $this_row_stock . '</td></tr>';
$result = mysql_query("
UPDATE products
SET pInStock = " . $this_row_stock . "
WHERE pId = '" . $row['pId'] . "'");
}
// Close files now that we're done with them
foreach ($filehandles as &$file)
{
fclose($file);
}
}