[eluser]Rey Philip Regis[/eluser]
example I have a table named test_table
test_table
id | description
1 | master & mind
2 | down to earth
3 | wonder woman
4 | clean the room
now, well outpt the data
$result = mysql_query("Select * from test_table");
.....
......
Then I'll output this in MS-Excel using headers. I created a function for this and I just need to pass the variable of the result set of the query I made above.
function displayToExcel($result)
{
ob_start("ob_gzhandler");
header("Content-Disposition: attachment; filename=campaign_excel.xls");
$i = 0;
while ($i < mysql_num_fields($result))
{
$field_name = mysql_field_name($result, $i);
$header .= $field_name."\t";
$i++;
}
while($row = mysql_fetch_row($result))
{
for($i = 0; $i < mysql_num_fields($result); $i++)
{
$data .= trim($row[$i])."\t";
}
$data .= "\n";
}
echo strtoupper($header)."\n".strtoupper(trim($data));
ob_end_flush();
}
But the problem is that, the output for the Master & Mind data in excel is just Master. The & Mind part is missing. Do you know how to solve this problem? I tried, replacing the & using str_replace with 'and' string, but it doesn't work and the output is still Master.