0
<?php
$server = 'xxxxxxxx';
$login = 'xxxxx';
$password = 'xxxxx';
$db = 'customers';
$table = 'account_id';
$filename = 'records.csv';
mysql_connect($server, $login, $password);
mysql_select_db($db);
$fp = fopen($filename, "w+");

$res = mysql_query("SELECT  `Emp_No` , `First_Name` , `Last_Nmae` ,  DATE_FORMAT( `Date`, '%b %d %Y' ), `Dept` , `Location` ,`Comment1`, `Comment2`
                   FROM $table
                   WHERE `Account` LIKE 'BJC100' 
                   AND  month(Date) >= 7 AND DATE_ADD(CURDATE(), INTERVAL -365 DAY) 
                   AND month(Date) <= 6 AND DATE_FORMAT( Date, '%Y' ) = DATE_FORMAT( NOW( ) , '%Y' ) AND length(Emp_No) > 0 ");

//July (7)anniversary

mysql_data_seek($res, 0);


while($row = mysql_fetch_assoc($res)) {

    $line = "";
    $comma = "";
    foreach($row as $value) {

     $line .= $comma . '' . str_replace('', '', $value) . '';

        $comma = ",";
    }
    $line .= "\n";
    fputs($fp, $line);

}

fclose($fp);
?>

所以我试图从上一年的 7 月 1 日到今年 6 月 30 日的记录如果我删除“AND month(Date) <= 6 AND DATE_FORMAT(Date, '%Y') = DATE_FORMAT(NOW(),' %Y' ) " 它将保存为 CSV 文件。一旦我把它放回去,它就会给我一个空白的 CSV 文件。

有人可以告诉我我做错了什么吗?

4

0 回答 0