Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-27-2009, 03:42 AM   PM User | #1
tiingshii
New Coder

 
Join Date: Aug 2009
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
tiingshii has a little shameless behaviour in the past
php table(read text file)

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
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
tiingshii is offline   Reply With Quote
Old 08-27-2009, 03:58 AM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
It looks good to me.
What do you mean by "spacing"?
mlseim is offline   Reply With Quote
Old 08-27-2009, 04:19 AM   PM User | #3
tiingshii
New Coder

 
Join Date: Aug 2009
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
tiingshii has a little shameless behaviour in the past


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

Last edited by tiingshii; 08-27-2009 at 04:48 AM..
tiingshii is offline   Reply With Quote
Old 08-27-2009, 08:34 AM   PM User | #4
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
Add cellspacing to your table.

Code:
<table cellspacing="5" summary="List of demo fields">
__________________
Dave .... HostMonster for all of your hosting needs
djm0219 is offline   Reply With Quote
Old 08-27-2009, 09:37 AM   PM User | #5
tiingshii
New Coder

 
Join Date: Aug 2009
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
tiingshii has a little shameless behaviour in the past
ah... that code create space between all rows.


But i only want a space when its another school.


is there another way?
thanks 4 helping me!

Last edited by tiingshii; 08-27-2009 at 10:32 AM..
tiingshii is offline   Reply With Quote
Old 08-27-2009, 02:24 PM   PM User | #6
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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;}

Last edited by mlseim; 08-27-2009 at 02:28 PM..
mlseim is offline   Reply With Quote
Old 08-28-2009, 03:07 AM   PM User | #7
tiingshii
New Coder

 
Join Date: Aug 2009
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
tiingshii has a little shameless behaviour in the past
hmmm.... i added in but there's no changes to the table..
tiingshii is offline   Reply With Quote
Old 08-28-2009, 03:47 AM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Create a class to control this (a CSS class, not a PHP one):
PHP Code:
$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?
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php

Last edited by Fou-Lu; 08-28-2009 at 03:48 AM.. Reason: needed some escaping :P
Fou-Lu is offline   Reply With Quote
Old 08-28-2009, 04:15 AM   PM User | #9
tiingshii
New Coder

 
Join Date: Aug 2009
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
tiingshii has a little shameless behaviour in the past
hahaha... T.T i tried creating it as a ccs class by put them in
Code:
<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---
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>

Last edited by tiingshii; 08-28-2009 at 04:46 AM..
tiingshii is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:09 AM.


Advertisement
Log in to turn off these ads.