1

Within a wordpress plugin, I have a PHP function which transform $file_name (a CSV file) into a table.

function displayAsTable($file_name)
{
echo '<table>';     
ini_set('auto_detect_line_endings',TRUE);
$f = fopen($file_name, "r");
while (($line = fgetcsv($f,0,",")) !== false) {
        echo '<tr>';
        echo '<td><input type="checkbox" name="addressXX" value="'.$line[2].'" name=""/></td>';
        foreach ($line as $cell) {
                echo '<td>' . htmlspecialchars($cell) . '</td>';
        }
        echo '<tr>';
}
fclose($f);
echo '</table>';
}

The problem is that I would like to add the new ROWS and COLUMNS into an existing TABLE within the same page! How could I do that easily?

2 Answers 2

3

Remove "echo <table>" and "echo </table>" and insert that function inside the existing table element. That should solve the problem because it will simply create new rows in addition to existing rows.

Sign up to request clarification or add additional context in comments.

Comments

0

I would change this function to:

function displayAsTable($file_name,$newTable = TRUE)
{
    if($newTable){ echo '<table>'; }
    //rest of code without last echo
    if($newTable){ echo '</table>'; }
}

And call it like: displayAsTable('rowstoappend.csv',false);

Comments

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.