note 30535 added to function.fgetcsv
| From: | mendi dot susanto at dmetrading dot com | Date: | Fri, 21 Mar 2003 07:07:12 +0000 |
| Subject: | note 30535 added to function.fgetcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-45596@lists.php.net to get a copy of this message | ||
I've tried the code above but doesn't work, so I tried to modify it... this is the code to
get the first line of csv fle, puti it into TABLE 1, while the rest line of csv file will be put at
TABLE 2
######################################
## Ini bagaimana cara mengimport file csv ke dalam
## database
## Gunakan ini untuk dasar mengolah file untuk dimasukkan
## ke dalam database
## VERY GOOD CODE
## Mengambil baris pertama untuk masuk ke TABEL 1 dan
## baris berikutnya di masukkan ke TABEL YANG LAIN
##########################################
$openfile = "tes2.csv";
$row = 0;
$handle = fopen ($openfile,"r");
while ($data = fgetcsv ($handle, 1000, ","))
{
if($row == '0')
{
$num = count ($data);
print "<p> $num fields in line $row: <br>\n";
echo "This belong to TABLE 1 <br>";
for ($c=0; $c < $num; $c++)
{
print $data[$c] . "<br>\n";
}
$row = '32';
}
else
{
$num = count ($data);
print "<p> $num fields in line $row: <br>\n";
$row++;
echo "This belong to TABLE 2 <br>";
for ($c=0; $c < $num; $c++)
{
print $data[$c] . "<br>\n";
}
}
}
fclose ($handle);
--
http://www.php.net/manual/en/function.fgetcsv.php
http://master.php.net/manage/user-notes.php?action=edit+30535
http://master.php.net/manage/user-notes.php?action=delete+30535
http://master.php.net/manage/user-notes.php?action=reject+30535