gpt4 book ai didi

php - 我的脚本有什么问题吗?

转载 作者:行者123 更新时间:2023-11-29 14:46:15 25 4
gpt4 key购买 nike

我正在尝试通过以下脚本将值插入到 csv 文件中...该脚本工作正常,但在输出中,这些值未按顺序正确排列...

<?php
require_once '../config.php';
$month = $_GET['month'];
$sq="select * from employee where month ='$month'";
$sql=mysql_query($sq);

$row = array();
$row[] = 'Employee Code';
$row[] = 'Employee Name';
$row[] = 'DOJ';
$data .= join(',', $row)."\n"; // Join all values without any trailing commas
$row = array(); // We must clear the previous values
while($rs = mysql_fetch_object($sql))
{
$row[] = $rs->employee_code;
$row[] = $rs->employee_name;
$row[] = $rs->emp_dateofjoin;
$row[] = "\n";
}
$data .= join(',', $row);

// Output the headers to download the file
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=test.csv");
header("Pragma: no-cache");
header("Expires: 0");
echo $data;
?>

这些值将添加到 csv 文件中,并在行的开头有一个空白单元格。除了第一行。

最佳答案

甚至不用看它,脚本的核心问题就在于您正在使用 mysql_* 函数。所以不要。您应该改为移至 PDO (太棒了),或mysqli (好)。

除此之外,您是否考虑过在查询中添加 ORDER BY 子句?

关于php - 我的脚本有什么问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6910456/

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