douliaodan2738 2016-11-25 18:42
浏览 46
已采纳

为什么我的桌子不出现?

My csv file has 3 columns for time, events, and location. I loaded each column into a separate array. Using a for loop, I displayed the arrays as an html table. However, it is not showing up. Why?

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>
";
        if ($i == 0){ //create table header cell
            echo "<th>";
            $time[$i];
            echo "</th>
";
            echo "<th>";
            $events[$i];
            echo "</th>
";
        }
        else {
            echo "<td class='cell-time'>";
            $time[$i];
            echo "</td>
";
            echo "<td class='cell-descript'>";
            $events[$i];
            echo "<br class = 'space'>";
            echo "<div class = 'table_description'>";
            echo "Location: " + $location[$i];
            echo "</div></td>
";
        }
        echo "</tr>
";
    }
    echo "
</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条回答 默认 最新

  • doujiaci7976 2016-11-25 19:03
    关注

    You have to concatenate your variables to the output string.

    You have:

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

    You need:

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

    When you concatenate, you use the . operator. Not +. Later on you are trying to:

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

    It should be:

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

    Read up on this here: http://php.net/manual/en/language.operators.string.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗