|
|
|
ช่วยด้วยค่ะ เรื่อง export .csv file แล้วบรรทัดสุดท้ายไม่มาครบ จะแก้ยังไงค่ะ |
|
|
|
|
|
|
|
ถ้ามาไม่ครบแสดงว่าเป็นที่ Query แล้วครับ
|
|
|
|
|
Date :
2016-01-09 14:40:48 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code ค่ะ แปลกอ่ะ ไม่เคยเจอ
Code (PHP)
if(!empty($row)) {
$filName = "Export-Database_Complex.csv";
$objWrite = fopen("Export-Database_Complex.csv", "w");
//$date_day = '2015-01-01';
//echo $Location_begin;
//echo $Number1_begin;
mysql_connect($pass->host_complex,$pass->user_complex,$pass->pwd_complex) or die ("Could not connect to MySQL at $pass->host_complex ");
mysql_query("SET NAMES UTF8");
$objDB = mysql_select_db($Location_begin);
if($Devices_begin == 'DV_6') {
$SQL_env = 'SELECT * FROM environment WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$env_0 = mysql_query($SQL_env) or die -("Error Query [".$SQL_env."]");
$SQL_inv_1 = 'SELECT * FROM inv_1 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_1 = mysql_query($SQL_inv_1) or die -("Error Query [".$SQL_inv_1."]");
$SQL_inv_2 = 'SELECT * FROM inv_2 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_2 = mysql_query($SQL_inv_2) or die -("Error Query [".$SQL_inv_2."]");
$SQL_inv_3 = 'SELECT * FROM inv_3 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_3 = mysql_query($SQL_inv_3) or die -("Error Query [".$SQL_inv_3."]");
$SQL_inv_4 = 'SELECT * FROM inv_4 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_4 = mysql_query($SQL_inv_4) or die -("Error Query [".$SQL_inv_4."]");
$SQL_inv_5 = 'SELECT * FROM inv_5 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_5 = mysql_query($SQL_inv_5) or die -("Error Query [".$SQL_inv_5."]");
$SQL_inv_6 = 'SELECT * FROM inv_6 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_6 = mysql_query($SQL_inv_6) or die -("Error Query [".$SQL_inv_6."]");
$SQL_inv_7 = 'SELECT * FROM inv_7 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_7 = mysql_query($SQL_inv_7) or die -("Error Query [".$SQL_inv_7."]");
$SQL_inv_8 = 'SELECT * FROM inv_8 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_8 = mysql_query($SQL_inv_8) or die -("Error Query [".$SQL_inv_8."]");
$SQL_inv_9 = 'SELECT * FROM inv_9 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_9 = mysql_query($SQL_inv_9) or die -("Error Query [".$SQL_inv_9."]");
$SQL_inv_10 = 'SELECT * FROM inv_10 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_10 = mysql_query($SQL_inv_10) or die -("Error Query [".$SQL_inv_10."]");
$SQL_inv_11 = 'SELECT * FROM inv_11 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_11 = mysql_query($SQL_inv_11) or die -("Error Query [".$SQL_inv_11."]");
$SQL_inv_12 = 'SELECT * FROM inv_12 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_12 = mysql_query($SQL_inv_12) or die -("Error Query [".$SQL_inv_12."]");
$SQL_inv_13 = 'SELECT * FROM inv_13 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_13 = mysql_query($SQL_inv_13) or die -("Error Query [".$SQL_inv_13."]");
$SQL_inv_14 = 'SELECT * FROM inv_14 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_14 = mysql_query($SQL_inv_14) or die -("Error Query [".$SQL_inv_14."]");
$SQL_inv_15 = 'SELECT * FROM inv_15 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_15 = mysql_query($SQL_inv_15) or die -("Error Query [".$SQL_inv_15."]");
$SQL_inv_16 = 'SELECT * FROM inv_16 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_16 = mysql_query($SQL_inv_16) or die -("Error Query [".$SQL_inv_16."]");
$SQL_inv_17 = 'SELECT * FROM inv_17 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_17 = mysql_query($SQL_inv_17) or die -("Error Query [".$SQL_inv_17."]");
$SQL_inv_18 = 'SELECT * FROM inv_18 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_18 = mysql_query($SQL_inv_18) or die -("Error Query [".$SQL_inv_18."]");
$SQL_inv_19 = 'SELECT * FROM inv_19 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_19 = mysql_query($SQL_inv_19) or die -("Error Query [".$SQL_inv_19."]");
$SQL_inv_20 = 'SELECT * FROM inv_20 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_20 = mysql_query($SQL_inv_20) or die -("Error Query [".$SQL_inv_20."]");
$SQL_inv_21 = 'SELECT * FROM inv_21 WHERE Ddate BETWEEN \''.$date_from_day.'\' AND \''.$date_to_day.'\' ORDER BY Ddate ASC, Dtime ASC';
$Inv_21 = mysql_query($SQL_inv_21) or die -("Error Query [".$SQL_inv_21."]");
$i=1;
fwrite($objWrite, "$Field_1 \n");
while($obj_env_0 = mysql_fetch_array($env_0)){
$obj_inv_1 = mysql_fetch_array($Inv_1);
$obj_inv_2 = mysql_fetch_array($Inv_2);
$obj_inv_3 = mysql_fetch_array($Inv_3);
$obj_inv_4 = mysql_fetch_array($Inv_4);
$obj_inv_5 = mysql_fetch_array($Inv_5);
$obj_inv_6 = mysql_fetch_array($Inv_6);
$obj_inv_7 = mysql_fetch_array($Inv_7);
$obj_inv_8 = mysql_fetch_array($Inv_8);
$obj_inv_9 = mysql_fetch_array($Inv_9);
$obj_inv_10 = mysql_fetch_array($Inv_10);
$obj_inv_11 = mysql_fetch_array($Inv_11);
$obj_inv_12 = mysql_fetch_array($Inv_12);
$obj_inv_13 = mysql_fetch_array($Inv_13);
$obj_inv_14 = mysql_fetch_array($Inv_14);
$obj_inv_15 = mysql_fetch_array($Inv_15);
$obj_inv_16 = mysql_fetch_array($Inv_16);
$obj_inv_17 = mysql_fetch_array($Inv_17);
$obj_inv_18 = mysql_fetch_array($Inv_18);
$obj_inv_19 = mysql_fetch_array($Inv_19);
$obj_inv_20 = mysql_fetch_array($Inv_20);
$obj_inv_21 = mysql_fetch_array($Inv_21);
if($obj_env_0[$y_1] == -1 ){ $Ty_1 = 'Error'; } else { $Ty_1 = $obj_env_0[$y_1]; }
if($obj_env_0[$y_3] == -1 ){ $Ty_3 = 'Error'; } else { $Ty_3 = $obj_env_0[$y_3]; }
if($obj_env_0[$y_5] == -1 ){ $Ty_5 = 'Error'; } else { $Ty_5 = $obj_env_0[$y_5]; }
if($obj_inv_1[$y_6] == -1 ){ $Ty_6 = 'Error'; } else { $Ty_6 = $obj_inv_1[$y_6]; }
if($obj_inv_2[$y_6] == -1 ){ $Ty_7 = 'Error'; } else { $Ty_7 = $obj_inv_2[$y_6]; }
if($obj_inv_3[$y_6] == -1 ){ $Ty_8 = 'Error'; } else { $Ty_8 = $obj_inv_3[$y_6]; }
if($obj_inv_4[$y_6] == -1 ){ $Ty_9 = 'Error'; } else { $Ty_9 = $obj_inv_4[$y_6]; }
if($obj_inv_5[$y_6] == -1 ){ $Ty_10 = 'Error'; } else { $Ty_10 = $obj_inv_5[$y_6]; }
if($obj_inv_6[$y_6] == -1 ){ $Ty_11 = 'Error'; } else { $Ty_11 = $obj_inv_6[$y_6]; }
if($obj_inv_7[$y_6] == -1 ){ $Ty_12 = 'Error'; } else { $Ty_12 = $obj_inv_7[$y_6]; }
if($obj_inv_8[$y_6] == -1 ){ $Ty_13 = 'Error'; } else { $Ty_13 = $obj_inv_8[$y_6]; }
if($obj_inv_9[$y_6] == -1 ){ $Ty_14 = 'Error'; } else { $Ty_14 = $obj_inv_9[$y_6]; }
if($obj_inv_10[$y_6] == -1 ){ $Ty_15 = 'Error'; } else { $Ty_15 = $obj_inv_10[$y_6]; }
if($obj_inv_11[$y_6] == -1 ){ $Ty_16 = 'Error'; } else { $Ty_16 = $obj_inv_11[$y_6]; }
if($obj_inv_12[$y_6] == -1 ){ $Ty_17 = 'Error'; } else { $Ty_17 = $obj_inv_12[$y_6]; }
if($obj_inv_13[$y_6] == -1 ){ $Ty_18 = 'Error'; } else { $Ty_18 = $obj_inv_13[$y_6]; }
if($obj_inv_14[$y_6] == -1 ){ $Ty_19 = 'Error'; } else { $Ty_19 = $obj_inv_14[$y_6]; }
if($obj_inv_15[$y_6] == -1 ){ $Ty_20 = 'Error'; } else { $Ty_20 = $obj_inv_15[$y_6]; }
if($obj_inv_16[$y_6] == -1 ){ $Ty_21 = 'Error'; } else { $Ty_21 = $obj_inv_16[$y_6]; }
if($obj_inv_17[$y_6] == -1 ){ $Ty_22 = 'Error'; } else { $Ty_22 = $obj_inv_17[$y_6]; }
if($obj_inv_18[$y_6] == -1 ){ $Ty_23 = 'Error'; } else { $Ty_23 = $obj_inv_18[$y_6]; }
if($obj_inv_19[$y_6] == -1 ){ $Ty_24 = 'Error'; } else { $Ty_24 = $obj_inv_19[$y_6]; }
if($obj_inv_20[$y_6] == -1 ){ $Ty_25 = 'Error'; } else { $Ty_25 = $obj_inv_20[$y_6]; }
if($obj_inv_21[$y_6] == -1 ){ $Ty_26 = 'Error'; } else { $Ty_26 = $obj_inv_21[$y_6]; }
fwrite($objWrite, "\"".$i++."\",\"$obj_env_0[Ddate]\",\"$obj_env_0[Dtime]\",\"$Ty_1\",\"$Ty_3\",\"$Ty_5\",\"$Ty_6\",\"$Ty_7\",\"$Ty_8\",\"$Ty_9\",\"$Ty_10\",\"$Ty_11\",\"$Ty_12\",\"$Ty_13\",\"$Ty_14\",\"$Ty_15\",\"$Ty_16\",\"$Ty_17\",\"$Ty_18\",\"$Ty_19\",\"$Ty_20\",\"$Ty_21\",\"$Ty_22\",\"$Ty_23\",\"$Ty_24\",\"$Ty_25\",\"$Ty_26\" \n");
}
fclose($objWrite);
$i=$i+1;
|
|
|
|
|
Date :
2016-01-11 09:35:21 |
By :
Jirata |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|