note 30535 modified in function.fgetcsv by aidan
| From: | aidan@php.net | Date: | Thu, 01 Jul 2004 01:04:17 +0000 |
| Subject: | note 30535 modified in function.fgetcsv by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72214@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
<?php
$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);
?>
--was--
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://php.net/manual/en/function.fgetcsv.php