2012-04-23 7 views
-1

現在のコードにエコーテーブルヘッダーを追加するにはどうすればよいですか?現在のコードにエコーテーブルヘッダーを追加するにはどうすればよいですか?

$ lines [0]は私のヘッダ行だけを印刷しますが、if文をエコーするときはまだ<th>です$ lines [0] else echo <tr>それは複数でエコーします空の<th>だから、誰かが助けることができたら少し失われてしまう。 schedule.txtの

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

私は私の問題が何であったのかを見て、私はTRをTHに、TDをTHに置き換えていました。 –

関連する問題