Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Aug 2009
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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

  2. #2
    Supreme Master coder!
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    10,097
    Thanks
    10
    Thanked 1,159 Times in 1,150 Posts
    It looks good to me.
    What do you mean by "spacing"?

  3. #3
    New Coder
    Join Date
    Aug 2009
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts


    something like this... spacing between each school
    izzit possible?
    Last edited by tiingshii; 08-27-2009 at 04:48 AM.

  4. #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    North Carolina
    Posts
    1,474
    Thanks
    4
    Thanked 231 Times in 228 Posts
    Add cellspacing to your table.

    Code:
    <table cellspacing="5" summary="List of demo fields">
    Dave .... HostMonster for all of your hosting needs

  5. #5
    New Coder
    Join Date
    Aug 2009
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  6. #6
    Supreme Master coder!
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    10,097
    Thanks
    10
    Thanked 1,159 Times in 1,150 Posts
    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.

  7. #7
    New Coder
    Join Date
    Aug 2009
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts
    hmmm.... i added in but there's no changes to the table..

  8. #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    17,026
    Thanks
    4
    Thanked 2,668 Times in 2,637 Posts
    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?
    Last edited by Fou-Lu; 08-28-2009 at 03:48 AM. Reason: needed some escaping :P
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  9. #9
    New Coder
    Join Date
    Aug 2009
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •