我得到了一个很好的片段,它在一个表上运行一个查询并将其打印为csv格式。
我对这个片段只有一个问题:
行中的一些数据是多行的,而不是一个单词。
现在的情况是,出口看起来是这样的:
消息名称电话
信息只在姓名和电话上传递,不限于我的姓名1800080808
(我希望'msg'的值在msg多维数据集中,而不是在name和phone中到处显示。)
你知道我怎么把一个值的整个短语放在一个框里吗?
代码段:

$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";
}

$filename = $file."_".date("d-m-Y_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");

print $csv_output;

提前谢谢!

最佳答案

您可以替换for循环中某个空格的所有新行:

$csv_output .= str_replace("\n", " ", $rowr[$j]).";";

09-05 11:01