You are here: Re: CSV into array « PHP Programming Language « IT news, forums, messages
Re: CSV into array

Posted by Tom on 10/12/05 19:50

Great, thanks for the tips. I've managed to overcome the hard bit now
:)

I've encountered a small problem that I can't figure out though....

My 1st page is a table with each of the products listed, with a
quantity form field for each product. The name of this field is qty1,
qty2 etc depending on which product it is. With me so far I hope....

The next page calls up the CSV again and loops through each line. I now
want to request the quantity form field for each product.

So I'm trying this

function convertCSVtoAssocMArray($file, $delimiter)
{
$result = Array();
$size = filesize($file) +1;
$file = fopen($file, 'r');
$keys = fgetcsv($file, $size, $delimiter);
while ($row = fgetcsv($file, $size, $delimiter))
{
for($i = 0; $i < count($row); $i++)
{
if(array_key_exists($i, $keys))
{
$row[$keys[$i]] = $row[$i];
}
}
$result[] = $row;
}
fclose($file);
return $result;
}


$myarray = convertCSVtoAssocMArray("sscreen.csv", ",");

$numElements = count($myarray);

for($counter=0; $counter < $numElements; $counter++)
{
$unitprice = $qty * $myarray[$counter][4];
echo $qty[$counter];
echo $counter;
}

But nothing is outputting! Any ideas? I basically need to construct the
$qty1 variable by adding the record count onto the end.

Again, thanks for all your help!

Tom

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация