Im currently working on php reading a text file. i managed to get the text showing orderly in a table. But there is an extra row between the title (school, date, time) and the first school (Anderson Primary School). How to remove that extra row?????? Anyone can help?
Lastly is there any ways that i can have a empty space between each school?
http://pddesignstudio.com/ckc/php2
php code
Code: Select all
<span class="style2">
<style type="text/css">
<!--
body, th, td, p, small {
font-family:'Times New Roman',Times,serif;
font-size:100%;
color:#757675;
}
small {font-size:90%;}
td, th {
background-color:#FFFFFF;
border:1px solid #CCCCCC;
padding:7px 20px 7px 20px;
}
th {background-color:#a5a5a5; color:#FFFFFF;}
h1 {font-size:120%; color:#558;}
h1 .sortby {color:#855;}
-->
</style>
</span>
<body>
<?php
echo '<h1><span class="sortby">'.$header.'</span></h1>
<table summary="List of demo fields">
<tr>
<th>Schools</th>
<th>Dates</th>
<th>Times</th>
</tr>';
$fp = fopen('flat-file-data2.txt','r');
if (!$fp) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;}
while (!feof($fp)) {
$line = fgets($fp,1024); //use 2048 if very long lines
$row++;
list ($schools, $dates, $times) = split ('\|', $line);
if ($sortby == 'schools') $sortkey = strtolower($schools);
if ($sortby == 'dates') $sortkey = strtolower($dates);
if ($sortby == 'times') $sortkey = strtolower($times);
$col[$row] = array($sortkey, $schools, $dates, $times);
}
fclose($fp);
$arrays = count($col) - 1;
$loop = -1;
while ($loop < $arrays) {
$loop++;
echo '
<tr>
<td>'.$col[$loop][1].'</td>
<td>'.$col[$loop][2].'</td>
<td>'.$col[$loop][3].'</td>
</tr>';
}
echo '
</table>
'?>Anderson Primary School|Monday 15 Dec 2009|2pm to 5pm
|Monday 15 Dec 2009|2pm to 5pm
|Monday 15 Dec 2009|2pm to 5pm
Ahmad Ibrahim Primary School|Monday 15 Dec 2009|2pm to 5pm
Chongfu Primary School|Monday 15 Dec 2009|2pm to 5pm
MacPherson Primary School|Monday 15 Dec 2009|2pm to 5pm
North View Primary School|Monday 15 Dec 2009|2pm to 5pm
Xishan Primary School|Monday 15 Dec 2009|2pm to 5pm