I am having trouble getting the first row of a csv file to display differnt than the rest.
I know this code works
<?
$filename = "ecgclibrary.csv";
$id = fopen($filename, "r");
while ($data = fgetcsv($id, filesize($filename), "|"))
{
$file_array[] = $data;
}
while (list(, $value) = each($file_array))
{
echo '<tr>';
echo '<td id="libdoc" class="libdoc1">' . $value[0] . '</td>';
echo '<td id="libdoc" class="libdoc1">' . $value[4] . '</td>';
echo '</tr>';
}
?>
but this code doesn't work
<?
$filename = "ecgclibrary.csv";
$id = fopen($filename, "r");
while ($data = fgetcsv($id, filesize($filename), "|"))
{
$file_array[] = $data;
}
$row = 0;
while (list(, $value) = each($file_array))
{
if ($row == 1)
{
echo '<tr>';
echo '<td id="libdoc" class="libdoc1">' . $value[0] . '</td>';
echo '<td id="libdoc" class="libdoc1">' . $value[4] . '</td>';
echo '</tr>';
}
if ($row == 2)
{
echo '<tr>';
echo '<td id="libdoc" class="libdoc2">' . $value[0] . '</td>';
echo '<td id="libdoc" class="libdoc2">' . $value[4] . '</td>';
echo '</tr>';
}
if ($row == 3)
{
echo '<tr>';
echo '<td id="libdoc" class="libdoc1">' . $value[0] . '</td>';
echo '<td id="libdoc" class="libdoc1">' . $value[4] . '</td>';
echo '</tr>';
$row = 1;
}
}
?>
I don't have an error or anything just a blank space were it's set to display.
I have been working with this for the last few days with no luck. I think I read almost every post on csv on this forum hoping to find an answer but found nothing.
Also, one note if you are wondering about the third "if ($row == 3)" I am using it to help alternate each rows background color for readability.