我需要的代碼是創建一個新的CSV並將其稱爲output_1.csv,將100行寫入該CSV,然後保存它,創建output_2.csv並寫入100行,並繼續創建100行文件,直到所有信息都用盡。有人可以幫我弄這個嗎?PHP和CSV文件+增量
這是我必須與之合作。目前,它只是寫入1個文件,直到所有內容都用完爲止。實際上,我需要一次做10萬行,但爲了測試目的,100行很好,我可以改變它。
<?php
include "base.php";
//$result1 = mysql_query("SELECT * FROM pts_ultd , scrape_data WHERE pts_ultd.B == scrape_data.R");
$a = "4";
$result1 = mysql_query("SELECT * FROM scrape_data , pts_ultd WHERE pts_ultd.P_B = scrape_data.S_R && pts_ultd.P_E != '".$a."' ");
//grab all the content
while($r=mysql_fetch_array($result1))
{
$A = $r["S_A"];
$B = $r["S_B"];
$C = $r["S_C"];
$D = $r["S_D"];
$E = $r["S_E"];
$F = $r["S_F"];
$G = $r["S_G"];
$H = $r["S_H"];
$I = $r["S_I"];
$J = $r["S_J"];
$K = $r["S_R"];
$L = $r["S_L"];
$M = $r["S_M"];
$N = $r["S_N"];
$O = $r["S_O"];
$P = $r["S_P"];
$Q = $r["S_Q"];
$R = $r["S_R"];
$S = $r["P_D"];
//this is where the intering of the data takes place currently..
$cvsData = $A . "," . $B . "," . $C . "," . $D . "," . $E . "," . $F . "," . $G . "," . $H . "," . $I . "," . $J . "," . $K . "," . $L . "," . $M . "," . $N . "," . $O . "," . $P . "," . $Q . "," . $R . "," . $S ."\n";
$fp = fopen("feed_output.csv","a"); // $fp is now the file pointer to file $filename
if($fp){
fwrite($fp,$cvsData); // Write information to the file
fclose($fp); // Close the file
} // end if
}//end while
?>
如果您提出具體問題,而不是要求人們爲您編寫代碼,您將會有更多的運氣。 – 2011-04-04 01:05:58