'' and $_REQUEST["end"]<>'') { $s-6ren">
gpt4 book ai didi

php - 如何使用 php 将 mysql 数据表搜索查询导出到 csv?

转载 作者:行者123 更新时间:2023-11-29 01:07:19 25 4
gpt4 key购买 nike

如何使用php将mysql数据表搜索查询导出为csv?

听到的是查询

if ($_REQUEST["startfrom"]<>'' and $_REQUEST["end"]<>'') {
$sql = "SELECT ECRNo,SalesDate,TimeSold,AmountDue,OutletName,ProductCode,Category,MealType,SUM(Quantity) AS Quantity1,SUM(NetPrice) AS NetPrice1 FROM ".$SETTINGS["data_table"]." WHERE SalesDate BETWEEN '".mysql_real_escape_string($_REQUEST["startfrom"])."'And'".mysql_real_escape_string($_REQUEST["end"])."'".$search_OutletName.$search_Category.$search_ProductCode.$search_groupby;
} else if ($_REQUEST["startfrom"]<>'') {
$sql = "SELECT ECRNo,SalesDate,TimeSold,AmountDue,SalesDate,OutletName,ProductCode,Category,MealType,SUM(Quantity) AS Quantity1,SUM(NetPrice) AS NetPrice1 FROM ".$SETTINGS["data_table"]." WHERE SalesDate >= '".mysql_real_escape_string($_REQUEST["startfrom"])."'".$search_OutletName.$search_Category.$search_ProductCode.$search_groupby;
} else if ($_REQUEST["end"]<>'') {
$sql = "SELECT ECRNo,SalesDate,TimeSold,SalesDate,AmountDue,OutletName,ProductCode,Category,MealType,SUM(Quantity) AS Quantity1,SUM(NetPrice) AS NetPrice1 FROM ".$SETTINGS["data_table"]." WHERE SalesDate <= '".mysql_real_escape_string($_REQUEST["end"])."'".$search_OutletName.$search_Category.$search_ProductCode.$search_groupby;
}else {
$sql = "SELECT ECRNo,SalesDate,TimeSold,SalesDate,AmountDue,OutletName,ProductCode,Category,MealType,SUM(Quantity) AS Quantity1,SUM(NetPrice) AS NetPrice1 FROM ".$SETTINGS["data_table"]." WHERE ECRNo>0 ".$search_OutletName.$search_Category.$search_ProductCode.$search_groupby;
}

如何导出查询结果?

最佳答案

所有好的答案都在这里,但如果您想使用 PHP 来完成,这里是另一种选择:

<?php

$list = array (
array('aaa', 'bbb', 'ccc', 'dddd'),
array('123', '456', '789'),
array('"aaa"', '"bbb"')
);

$fp = fopen('file.csv', 'w');

foreach ($list as $fields) {
fputcsv($fp, $fields);
}

fclose($fp);
?>

$list 数组将是您从数据库中得到的结果。

摘自here

关于php - 如何使用 php 将 mysql 数据表搜索查询导出到 csv?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18736785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com