2012-04-23 52 views
-1

我該如何添加回顯表頭到我目前的代碼?如何添加回顯表頭到我目前的代碼?

我有點失落,因爲$ lines [0]只打印我的標題行,但是當我執行if語句時,如果$ lines [0] else echo <tr>它回顯出多個空<th>的,所以我有點失落,如果有人可以幫助。自定的

function schedule_gen() 
{ 
    //set file 
    $filename='schedule.txt'; 
    //open 
    $handler=fopen('schedule.txt','r'); 
    //read through file 
    $file=fread($handler,filesize($filename)); 

    //start table creation 
    echo "<table id='schedule_table'>"; 

    //split into array by return\linefeed 
    $lines=explode("\r\n",$file); 

    //loop through rows 
    for($i=0;$i<count($lines);$i++) 
    { 
     //if not blank then print row 
     if($lines[$i]!=""&&$lines[$i]!=" ") 
     { 

      echo "<tr class='schedule_row'>"; 

      //split into array by commas 
      $items=explode("\t",$lines[$i]); 
      //loop through cells 
      for($j=0;$j<count($items);$j++) 
      { 
       //if not blank then print cell 
       if($items[$j]!=""&&$items[$j]!=" ") 
       { 
        echo "<td class='schedule_cell'>".$items[$j]."</td>"; 
       } 
      } 
      echo "</tr>"; 
     } 
    } 
    echo "</table>"; 
    //end table creation 

    fclose($handle); 
    //close file 
} 

例子:

Employee/schedule restrictions Thur 4/26 Fri 4/27 Sat 4/28 Sun 4/29 Mon 4/30 Tue 5/1 Wed 5/2 
Administrative       
Assistant 8a-4 8a-4 no no 8a-4p 8a-4p 8a-4p 

QC Team -Manager        
QC team/no Tues or Sat 8a-4 8a-4 no 8a-4p 8a-4p no 8a-4p 
QC team 6p-2a 6p-2a 6p-2a no 6p-2a 6p-2a 

回答

1

不太清楚,如果我讀了你的問題的權利,但是這是你需要什麼?

function schedule_gen() 
{ 
//set file 
$filename='schedule.txt'; 
//open 
$handler=fopen('schedule.txt','r'); 
//read through file 
$file=fread($handler,filesize($filename)); 

//start table creation 
echo "<table id='schedule_table'>"; 

//split into array by return\linefeed 
$lines=explode("\r\n",$file); 

//loop through rows 
for($i=0;$i<count($lines);$i++) 
{ 
//if not blank then print row 
if($lines[$i]!=""&&$lines[$i]!=" ") 
{ 
$t_type="td"; 
if($i==0){$t_type="th";} 

//split into array by commas 
$items=explode("\t",$lines[$i]); 
//loop through cells 
for($j=0;$j<count($items);$j++) 
{ 
//if not blank then print cell 
if($items[$j]!=""&&$items[$j]!=" ") 
{ 
echo "<$t_type class='schedule_cell'>".$items[$j]."</$t_type>"; 
} 
} 
echo "</tr>"; 
} 
} 
echo "</table>"; 
//end table creation 

fclose($handle); 
//close file 
} 
+0

噢好吧我明白我的問題是什麼,derp,我用TH代替TR,而不用TH代替TD。 – 2012-04-23 15:48:33

相關問題