I have a DB that contains user registrations for events. I want to make a UDT to create a csv file for download so that the users can see the registered users for that event. I have the php done that creates the file and lets the dl occur. It works great outside of cmsms.
When i create the udt and call in from my page, the download occurs, execpt all the html is output into the csv file above the database records. Any idea how i can get this to work.
Here is the code in my UDT Called Download_Registrations:
Code: Select all
$host = 'xxxxx';
$user = 'xxxxx';
$pass = 'xxxx';
$db = 'xxxx';
$table = 'user_reg';
$file = 'export';
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");
$result = mysql_query("SHOW COLUMNS FROM ".$table."");
$i = 0;
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_assoc($result))
{
$csv_output .= $row['Field'].", ";
$i++;
}
}
$csv_output .= "\n";
$values = mysql_query("SELECT * FROM ".$table."");
while ($rowr = mysql_fetch_row($values))
{
for ($j=0;$j<$i;$j++)
{
$csv_output .= $rowr[$j].", ";
}
$csv_output .= "\n";
}
print $csv_output;
exit;
the output file starts with the tag and continues down until my db records start. how can i get rid of the html code in this file that is generated from cmsms? Any other ideas?