Skip to content

Instantly share code, notes, and snippets.

@jasonglisson
Last active September 14, 2017 12:41
Show Gist options
  • Select an option

  • Save jasonglisson/420d393e7cb32f71939b to your computer and use it in GitHub Desktop.

Select an option

Save jasonglisson/420d393e7cb32f71939b to your computer and use it in GitHub Desktop.

Revisions

  1. jasonglisson revised this gist Sep 14, 2017. No changes.
  2. jasonglisson revised this gist Feb 9, 2016. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion table_render.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    $rows = 1;
    if (($handle = fopen($row->field_field_results_data_file[0]['raw']['uri'], "r")) !== FALSE) {

    if (($handle = fopen("<path to csv file>", "r")) !== FALSE) {

    echo '<table class="table table-bordered toggle-square-filled default breakpoint footable">';

  3. jasonglisson created this gist Feb 9, 2016.
    40 changes: 40 additions & 0 deletions table_render.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    $rows = 1;
    if (($handle = fopen($row->field_field_results_data_file[0]['raw']['uri'], "r")) !== FALSE) {

    echo '<table class="table table-bordered toggle-square-filled default breakpoint footable">';

    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $num = count($data);
    if ($rows == 1) {
    echo '<thead><tr>';
    } else {
    echo '<tr>';
    }

    for ($c=0; $c < $num; $c++) {
    //echo $data[$c] . "<br />\n";
    if(empty($data[$c])) {
    $value = "&nbsp;";
    } else {
    $value = $data[$c];
    }
    if ($rows == 1) {
    echo '<th>'.$value.'</th>';
    } else {
    echo '<td>'.$value.'</td>';
    }
    }

    if ($rows == 1) {
    echo '</tr></thead><tbody>';
    } else {
    echo '</tr>';
    }
    $rows++;
    }

    echo '</tbody></table>';
    fclose($handle);
    } else {
    echo '<h4>No CSV file found</h4>';
    }