php
  • html
  • arrays
  • csv
  • 2016-11-25 26 views 0 likes 
    0

    私のcsvファイルには、時間、イベント、および場所の3つの列があります。私は別の配列に各列を読み込んだ。 forループを使用して、配列をhtmlテーブルとして表示しました。しかし、それは表示されません。どうして?テーブルが表示されないのはなぜですか?

    EventsScheduleFriday.php

    <?php 
    echo "<link rel='stylesheet' type='text/css' href='../styles/styles.css' />"; 
    
    $time = array(); 
    $events = array(); 
    $location = array(); 
    
    function get_data(&$time, &$events, &$location) { //references variable declared above 
        $file = fopen(__DIR__."/../data/EventsScheduleFriday.csv", "r"); 
        while(!feof($file)) { //while end of file has not been reached 
         $content = fgetcsv($file, ","); //converts first line of csv to an array 
         array_push($time, $content[0]); 
         array_push($events, $content[1]); 
         array_push($location, $content[2]); 
        } 
        fclose($file); //closes csv file 
    } 
    
    // put the data on the screen in readable form 
    function display_table(&$time, &$events, &$location) { 
        echo "<table class='tg'>"; 
        for($i = 0; $i < count($time); $i++) { 
         echo "<tr>\n"; 
         if ($i == 0){ //create table header cell 
          echo "<th>"; 
          $time[$i]; 
          echo "</th>\n"; 
          echo "<th>"; 
          $events[$i]; 
          echo "</th>\n"; 
         } 
         else { 
          echo "<td class='cell-time'>"; 
          $time[$i]; 
          echo "</td>\n"; 
          echo "<td class='cell-descript'>"; 
          $events[$i]; 
          echo "<br class = 'space'>"; 
          echo "<div class = 'table_description'>"; 
          echo "Location: " + $location[$i]; 
          echo "</div></td>\n"; 
         } 
         echo "</tr>\n"; 
        } 
        echo "\n</table>"; 
    } 
    
    get_data($time, $events, $location); 
    display_table($time, $events, $location); 
    
    
    ?> 
    

    EventsScheduleFriday.csv

    Time,Event,Location, 
    12:30pm,Hilby The Skinny German Juggle Boy,West State Street, 
    4:45pm,Hilby The Skinny German Juggle Boy,West State Street, 
    6pm,Finger Lakes Comedy Festival Competition 1st Round (Age 21+),Lot 10, 
    8pm,Stand-up Comedy Show,Acting Out NY, 
    10pm,All-Star Comedy Show,Acting Out NY 
    

    events.php

    <div class = "schedule"> 
           <?php include "scripts/EventsScheduleFriday.php" ?> 
    </div> 
    

    答えて

    1

    変数を出力文字列に連結する必要があります。

    は、あなたが持っている:

    echo "<th>"; 
    $time[$i]; 
    

    をあなたは必要とする:あなたが連結すると

    echo "<th>" . $time[$i]; 
    

    は、あなたが.演算子を使用します。 Not +。あなたがしようとしている、後に:

    echo "Location: " + $location[$i];

    それは次のようになります。

    ここで、この上に読んで

    echo "Location: " . $location[$i];

    http://php.net/manual/en/language.operators.string.php

    関連する問題