0

I am trying to format the csv reader to come out in that way: 1. somestuff, somestuff2, somestuff3 unfortunately the numbers are wrapping up at the top of the table instead of in beginning of the line. any help?

    <?php
        $row = 1;
        $handle = fopen("random.csv", "r");
        $number = 1;
        echo("<table>");
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
            echo($number . "." . " " . "<tr>\r\n");
            foreach ($data as $index=>$val) {

                echo("\t<td>$val</td>\r\n");
            }
            echo("</tr>\r\n");
            $numer ++;
        }
        echo("</table>");
        fclose($handle);
    ?>
1
  • Numbers should be inside <td> and not where you like them to be. Commented May 19, 2016 at 7:51

1 Answer 1

1

You should create a new cell for those numbers:

<?php
    $handle = fopen("random.csv", "r");
    $number = 1;
    echo '
    <table>';
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        echo '
      <tr>
        <td>' . $number . '.</td>';

        foreach ($data as $index => $val) {
            echo '
        <td>' . $val . '</td>';
        }
        echo '
      </tr>';
        $number ++;
    }
    echo '
    </table>';
    fclose($handle);
Sign up to request clarification or add additional context in comments.

1 Comment

It is still on the top.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.