|
|
|
PHP สอบถามเรื่องการดึงค่าจาก Database แล้ววนลูปลง Excel ครับ |
|
|
|
|
|
|
|
Code (Example)
// Write data from MySQL result
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer";
$objQuery = mysql_query($strSQL);
$i = 2;
while($objResult = mysql_fetch_array($objQuery))
{
$objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $objResult["CustomerID"]);
$objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $objResult["Name"]);
$objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $objResult["Email"]);
$objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $objResult["CountryCode"]);
$objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $objResult["Budget"]);
$objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $objResult["Used"]);
$i++;
}
mysql_close($objConnect);
|
|
|
|
|
Date :
2014-08-25 09:55:51 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
function int2ExcelColumn($id){
$alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$column = ''; $num=$id;
while($num){
$a = $num % 26;
$num = Math.floor(($num / 26);
$column = substr( $alpha, $a, 1) . $column;
}
return $column;
}
|
|
|
|
|
Date :
2014-08-25 15:33:18 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|