...

View Full Version : php table(read text file)



tiingshii
08-27-2009, 04:42 AM
i have this working ----- http://pddesignstudio.com/ckc/php2

now i want to create spacing between each school how do i do it?
can anyone help mi its my first time dealing with php

PHP CODE

1. <span class="style2">
2. <style type="text/css">
3. <!--
4. body, th, td, p, small {
5. font-family:'Times New Roman',Times,serif;
6. font-size:100%;
7. color:#757675;
8. }
9. small {font-size:90%;}
10.
11. td, th {
12. background-color:#FFFFFF;
13. border:1px solid #CCCCCC;
14. padding:7px 20px 7px 20px;
15. }
16. th {background-color:#a5a5a5; color:#FFFFFF;}
17.
18. h1 {font-size:120%; color:#558;}
19. h1 .sortby {color:#855;}
20. -->
21. </style>
22. </span>
23.
24. <body>
25.
26. <?php
27. echo '<h1><span class="sortby">'.$header.'</span></h1>
28. <table summary="List of demo fields">
29. <tr>
30. <th>Schools</th>
31. <th>Dates</th>
32. <th>Times</th>
33. </tr>';
34.
35. $fp = fopen('flat-file-data2.txt','r');
36. if (!$fp) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;}
37.
38. while (!feof($fp)) {
39. $line = fgets($fp,1024); //use 2048 if very long lines
40. $row++;
41. list ($schools, $dates, $times) = split ('\|', $line);
42. if ($sortby == 'schools') $sortkey = strtolower($schools);
43. if ($sortby == 'dates') $sortkey = strtolower($dates);
44. if ($sortby == 'times') $sortkey = strtolower($times);
45. $col[$row] = array($sortkey, $schools, $dates, $times);
46. }
47.
48. fclose($fp);
49.
50. $arrays = count($col) - 1;
51.
52. $loop = 0;
53. while ($loop < $arrays) {
54. $loop++;
55. echo '
56. <tr>
57. <td>'.$col[$loop][1].'</td>
58. <td>'.$col[$loop][2].'</td>
59. <td>'.$col[$loop][3].'</td>
60. </tr>';
61. }
62.
63. echo '
64. </table>
65.
66. '?>

.txt
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

mlseim
08-27-2009, 04:58 AM
It looks good to me.
What do you mean by "spacing"?

tiingshii
08-27-2009, 05:19 AM
http://pddesignstudio.com/ckc/spacing2

something like this... spacing between each school
izzit possible?

djm0219
08-27-2009, 09:34 AM
Add cellspacing to your table.



<table cellspacing="5" summary="List of demo fields">

tiingshii
08-27-2009, 10:37 AM
ah... that code create space between all rows.
http://pddesignstudio.com/ckc/spacing3

But i only want a space when its another school.
http://pddesignstudio.com/ckc/spacing2

is there another way?
thanks 4 helping me!

mlseim
08-27-2009, 03:24 PM
Try adding the CSS tag (shown in blue).


td, th {
background-color:#FFFFFF;
border:1px solid #CCCCCC;
padding:7px 20px 7px 20px;
}
th {background-color:#a5a5a5; color:#FFFFFF;}

tr {padding-bottom:15px;}

tiingshii
08-28-2009, 04:07 AM
hmmm.... i added in but there's no changes to the table..

Fou-Lu
08-28-2009, 04:47 AM
Create a class to control this (a CSS class, not a PHP one):


$loop = 0;
$mLastSchool = null;
while ($loop < $arrays) {
$loop++;
if ($mLastSchool != $col[$loop][1])
{
echo '<tr class=\'newSchool\'>';
$mLastSchool = $col[$loop][1];
}
else
{
echo '<tr>';
}
echo '<td>'.$col[$loop][1].'</td>
<td>'.$col[$loop][2].'</td>
<td>'.$col[$loop][3].'</td>
</tr>';
}



Define newSchool css with mlseim's margin or padding bottom.
Does that work?

tiingshii
08-28-2009, 05:15 AM
hahaha... T.T i tried creating it as a ccs class by put them in

<STYLE TYPE="text/css">
<!-- $arrays = count($col) - 1;

$loop = 0;
$mLastSchool = null;
while ($loop < $arrays) {
$loop++;
if ($mLastSchool != $col[$loop][1])
{
echo '<tr class=\'newSchool\'>';
$mLastSchool = $col[$loop][1];
}
else
{
echo '<tr>';
}
echo '<td>'.$col[$loop][1].'</td>
<td>'.$col[$loop][2].'</td>
<td>'.$col[$loop][3].'</td>
</tr>';
}
-->
</STYLE> (inside php and the whole table disappear)


how do you do it? and where to put? im totally a newbie >.<

---whole code---

<style type="text/css">
<!--
#apDiv1 {
position:absolute;
width:749px;
height:520px;
z-index:1;
left: 302px;
top: 80px;
}
-->
</style>
</head>
<body>

<div id="apDiv1">
<style type="text/css">
<!--
#apDiv1 {
position:absolute;
width:800px;
height:115px;
z-index:1;
}
-->
</style>
</head>

<body>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

<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;
text-align:center;
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 width ="700" summary="List of demo fields">
<tr>
<th>Schools</th>
<th>Dates</th>
<th>Times</th>
</tr>';

$fp = fopen('sellingDate.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);

<STYLE TYPE="text/css">
<!--
$arrays = count($col) - 1;

$loop = 0;
$mLastSchool = null;
while ($loop < $arrays) {
$loop++;
if ($mLastSchool != $col[$loop][1])
{
echo '<tr class=\'newSchool\'>';
$mLastSchool = $col[$loop][1];
}
else
{
echo '<tr>';
}
echo '<td>'.$col[$loop][1].'</td>
<td>'.$col[$loop][2].'</td>
<td>'.$col[$loop][3].'</td>
</tr>';
}
-->
</STYLE>
}

echo '</table>

'?> </div>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum