|
|
|
สอบถามเรื่อง mysql to csv หน่อย ครับ ผมขอถามเกี่ยวกับการ select mysql มาเป็น csv หน่อย ครับ |
|
|
|
|
|
|
|
ผมขอถามเกี่ยวกับการ select mysql มาเป็น csv หน่อย ครับ ลองทำแบบ ภาษาเปนแบบตามรูป ครับ
นี้ ครับ
Code (PHP)
<html>
<head>
<title>:: GTD Generate Excel ::</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="images/tsc.ico" />
<link href="addmin.css" rel="stylesheet" type="text/css" />
<link href="ptsand.css" rel="stylesheet" type="text/css">
</head>
<body>
<? include "include/topmenu-admin.php"; ?>
<center>
<br />
<form id="form1" name="form1" method="post" action="report2.php">
<p> </p>
<p> </p>
<p> </p>
<table width="200" border="0">
<tr>
<td><select class="textfield2" name="day1" id="day1">
<option class="textfield2" value=""> Date </option>
<?
for ($i=1;$i<=31;$i++) {
echo "<OPTION VALUE='$i'>$i</OPTION>";
}
?>
</select></td>
<td><select class="textfield2" name="month1" id="month1">
<option class="textfield2" value=""> Month </option>
<?
$thai_m=array("","January","February ","March ","April ","May ","June ","July ",
"August ","September ","October ","November ","December ");
for ($i=1;$i<=12;$i++) {
echo "<OPTION VALUE='$i'>$thai_m[$i]</OPTION>";
}
?>
</select></td>
<td><select class="textfield2" name="year1" id="year1">
<option class="textfield2" value=""> Year </option>
<?
for ($i=2005;$i<=2015;$i++) {
$y=$i;
echo "<OPTION VALUE='$i'>$y</OPTION>";
}
?>
</select></td>
<td align="center">
<h2>To </h2></td>
<td><select class="textfield2" name="day2" id="day2">
<option class="textfield2" value=""> Date </option>
<?
for ($i=1;$i<=31;$i++) {
echo "<OPTION VALUE='$i'>$i</OPTION>";
}
?>
</select></td>
<td><select class="textfield2" name="month2" id="month2">
<option class="textfield2" value=""> Month </option>
<?
$thai_m=array("","January","February ","March ","April ","May ","June ","July ",
"August ","September ","October ","November ","December");
for ($i=1;$i<=12;$i++) {
echo "<OPTION VALUE='$i'>$thai_m[$i]</OPTION>";
}
?>
</select></td>
<td><select class="textfield2" name="year2" id="year2">
<option class="textfield2" value=""> Year </option>
<?
for ($i=2005;$i<=2015;$i++) {
$y=$i;
echo "<OPTION VALUE='$i'>$y</OPTION>";
}
?>
</select></td>
</tr>
<tr>
<td height="35"> </td>
<td> </td>
<td> </td>
<td><input class="button_gray" type="submit" name="button" id="button" value="Export" /></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<p> </p>
</form>
<br />
<?
$day1=$_POST[day1];
$month1=$_POST[month1];
$year1=$_POST[year1];
$day2=$_POST[day2];
$month2=$_POST[month2];
$year2=$_POST[year2];
include "connect.php";
if($day1=="" or $month1=="" or $year1=="" or $day2=="" or $month2=="" or $year2==""){
echo"<center><h3> Select data<br></h3><br><br><br></center>"; exit();
}else{
echo"<h2> $year1-$month1-$day1 to $year2-$month2-$day2 </h2><br><br>";
$filName = "reportGTD.csv";
$objWrite = fopen("reportGTD.csv", "w");
$objDB = mysql_select_db("calendar");
$strSQL="select * from car where timeback BETWEEN '$year1-$month1-$day1' AND '$year2-$month2-$day2'";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
fwrite($objWrite, "\"$objResult[name]\",\"$objResult[locate]\",\"$objResult[typeap]\",");
fwrite($objWrite, "\"$objResult[flight]\",\"$objResult[arrive]\",\"$objResult[typecar]\" \n");
}
fclose($objWrite);
echo "<br><Center><br>Generate ReportGTD Done.<br><a href=$filName>Download</a>";
}
?>
<div style="clear:both"></div>
</div>
<div style="clear:both;"></div>
</div>
</body>
</html>
Tag : PHP
|
|
|
|
|
|
Date :
2013-07-23 13:30:13 |
By :
wave1232 |
View :
674 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ภาษาผมแก้แล้วครับใส่ใน script connect
Code (PHP)
<?
$host="localhost";
$user="root";
$pw="1234";
$dbname="calendar";
$c = mysql_connect($host,$user,$pw);
if (!$c) {
echo "<h3>Can't connect DB</h3>";
exit();
}
mysql_select_db($dbname);
mysql_query("SET NAMES utf8");
mysql_query("SET CHARACTER SET utf8");
?>
ก้อยังไม่หาย ครับ
|
|
|
|
|
Date :
2013-07-23 18:25:30 |
By :
wave1232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|