I’m trying to read the contents of a CSV file and enter it directly into the
value field of a specific TV.
The code below works as far as generating the the <table> layout and content from the CSV file, if I use echo/print etc. the tabled HTML content is generated okay.
How do I get it into the DB from the
$buffer ?
I must be missing something obvious to the proper PHP coders out there!
<?php
$filename = "assets/files/companies.csv";
$buffer = '';
$buffer.='<table style="border:0; cellspacing:0; cellpadding:5; width:80%; font-size:10pt;">'."\r\n";
$file_handle = fopen("$filename", "r");
while (!feof($file_handle))
{
$rowdata = fgetcsv($file_handle, 1024);
$buffer.= '<tr><td>'.$rowdata[0].'</td><td>'.$rowdata[1].'</td><td>'.$rowdata[2].'</td><td>'.$rowdata[3].'</td></tr>'."\r\n";
}
$buffer.= '</table>';
$insert = mysql_query('INSERT INTO `modx_site_tmplvar_contentvalues` (`tmplvarid`,`contentid`, `value`) VALUES (11, 1027, "'.$buffer.'")');
fclose($file_handle);
?>