Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > สอบถามเรื่อง ดึงข้อมูลจากหลายตารางมา query แล้ว export เป็น excel ค่ะ



 

สอบถามเรื่อง ดึงข้อมูลจากหลายตารางมา query แล้ว export เป็น excel ค่ะ

 



Topic : 095668



โพสกระทู้ ( 89 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook



ต้องการดึงข้อมูลจากหลายตารางเช่น
ตาราง brand
ตาราง no
ตาราง FG
ต้องการดึง ข้อมูลจาก 3 ตารางนี้แล้วแสดง แยกทีละ brand,no แต่ให้แสดงอยู่ในหน้าเดียวกันแล้ว export to excel เมื่อ query มาแล้ว export ออกมาเป็น excel แล้วปรากฎว่าไม่มีข้อมูลออกมาค่ะ มีแต่หัวตาราง แต่หาก query ธรรมดา ไม่ export to excel ข้อมูลโชว์ปกติ



Tag : PHP, MySQL









ประวัติการแก้ไข
2013-05-25 10:08:56
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-05-25 10:07:59 By : supattra.s View : 968 Reply : 2
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

เอา Query มาดูครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-05-25 10:28:46 By : mr.win
 


 

No. 2



โพสกระทู้ ( 89 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=tis620" />
<title>Untitled Document</title>
</head>
<body>
<?
$id_brand=$_POST[id_brand];
$objConnect = mysql_connect("localhost","root","admin") or die("Error Connect to Database");
$objDB = mysql_select_db("invoine");
mysql_query("SET NAMES TIS620");
$strSQL3 = "SELECT * FROM no";
$objQuery3 = mysql_query($strSQL3) or die ("Error Query [".$strSQL3."]");

while($objResult3 = mysql_fetch_array($objQuery3))
{

?>
<?
$strSQL5 = "SELECT * FROM brand where id_brand = '$id_brand'";
$objQuery5= mysql_query($strSQL5) or die ("Error Query [".$strSQL5."]");

while($objResult5 = mysql_fetch_array($objQuery5))

{
?>
<?
$strSQL = "select * from customer where id_brand='$id_brand' and id_no='".$objResult3["id_no"]."' order by id_no,date,area";
echo $strSQL;
$objQuery = mysql_query($strSQL);
if($objQuery)
{
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["C:/AppServ/www/inv2"]))); // C:/AppServ/www/myphp

//*** Excel Document Root ***//
$strFileName = "stockfg.xls";

//*** Connect to Excel.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Add();


//*** Create Sheet 1 ***//
$xlBook->Worksheets(1)->Name = "Stock FG";
$xlBook->Worksheets(1)->Select;

//*** Width & Height (A1:A1) ***//
$xlApp->ActiveSheet->Range("A1:A1")->ColumnWidth = 10.0;
$xlApp->ActiveSheet->Range("B1:B1")->ColumnWidth = 13.0;
$xlApp->ActiveSheet->Range("C1:C1")->ColumnWidth = 8.0;
$xlApp->ActiveSheet->Range("D1:D1")->ColumnWidth = 12.0;
$xlApp->ActiveSheet->Range("E1:E1")->ColumnWidth = 13.0;
$xlApp->ActiveSheet->Range("F1:F1")->ColumnWidth = 13.0;


//*** Report Title ***//
$xlApp->ActiveSheet->Range("A1:E1")->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Range("A1:E1")->MergeCells = True;
$xlApp->ActiveSheet->Range("A1:E1")->Font->Bold = True;
$xlApp->ActiveSheet->Range("A1:E1")->Font->Size = 18;
$xlApp->ActiveSheet->Range("A1:E1")->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(2,2)->Value = "แบรนด์ $objResult5[name_brand] เบอร์ $objResult3[name_no]";
// head brand
$xlApp->ActiveSheet->Range("A2:E2")->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Range("A2:E2")->MergeCells = True;
$xlApp->ActiveSheet->Range("A2:E2")->Font->Size =14;
$xlApp->ActiveSheet->Range("A2:E2")->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(1,1)->Value = "บริษัทไทยยูเนี่ยนฟีดมิลล์ จำกัด";
//*** Header ***//
$xlApp->ActiveSheet->Cells(3,1)->Value = "วันที่";
$xlApp->ActiveSheet->Cells(3,1)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,1)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,1)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,1)->BORDERS->Weight = 1;

$xlApp->ActiveSheet->Cells(3,2)->Value = "ล็อก";
$xlApp->ActiveSheet->Cells(3,2)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,2)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,2)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,2)->BORDERS->Weight = 1;

$xlApp->ActiveSheet->Cells(3,3)->Value = "จำนวน";
$xlApp->ActiveSheet->Cells(3,3)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,3)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,3)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,3)->BORDERS->Weight = 1;

$xlApp->ActiveSheet->Cells(3,4)->Value = "อายุปัจจุบัน";
$xlApp->ActiveSheet->Cells(3,4)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,4)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,4)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,4)->BORDERS->Weight = 1;

$xlApp->ActiveSheet->Cells(3,5)->Value = "สถานะ";
$xlApp->ActiveSheet->Cells(3,5)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,5)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,5)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,5)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,6)->Value = "เบอร์";
$xlApp->ActiveSheet->Cells(3,6)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,6)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,6)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,6)->BORDERS->Weight = 1;

//***********//

$intRows = 4;
while($objResult = mysql_fetch_array($objQuery))
{
$date_t = $objResult["date"];
$detail=$objResult["detail"];

if ($detail=='') {
$detail='-';
}





?>
<?
$birthday = $date_t; //???????????????????
$today = date("Y-m-d"); //??????????

$r = mysql_query("SELECT DATEDIFF( '$today', '$date_t' )+1 AS date
FROM customer");

while($row = mysql_fetch_array($r)){

$d_d_back=$row['date'];
}


?>
<?

//*** Detail ***//
$xlApp->ActiveSheet->Cells($intRows,1)->Value = $objResult["date"];
$xlApp->ActiveSheet->Cells($intRows,1)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,1)->HorizontalAlignment = -4108;

$xlApp->ActiveSheet->Cells($intRows,2)->Value = $objResult["area"];
$xlApp->ActiveSheet->Cells($intRows,2)->BORDERS->Weight = 1;

$xlApp->ActiveSheet->Cells($intRows,3)->Value = $objResult["total"];
$xlApp->ActiveSheet->Cells($intRows,3)->BORDERS->Weight = 1;

$xlApp->ActiveSheet->Cells($intRows,4)->Value = $d_d_back;
$xlApp->ActiveSheet->Cells($intRows,4)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,4)->BORDERS->Weight = 1;

$xlApp->ActiveSheet->Cells($intRows,5)->Value = $objResult["status"];
$xlApp->ActiveSheet->Cells($intRows,5)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,5)->BORDERS->Weight = 1;


$xlApp->ActiveSheet->Cells($intRows,6)->Value = $objResult["id_no"];
$xlApp->ActiveSheet->Cells($intRows,6)->BORDERS->Weight = 1;



$intRows++;

}
@unlink($strFileName); //*** Delete old files ***//

$xlBook->SaveAs($strPath."/".$strFileName); //*** Save to Path ***//

//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;
}

}
}

mysql_close($objConnect);

?>
Excel Created <a href="<?=$strFileName?>">Click here</a> to Download.
</body>
</html>
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-05-25 10:38:42 By : supattra.s
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถามเรื่อง ดึงข้อมูลจากหลายตารางมา query แล้ว export เป็น excel ค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่