|
|
|
สอบถามว่า ต้องเขียน Code อย่างไร จึงจะรวมไฟล์ excel1.php - excel3.php ให้กลายเป็นไฟล์ excel.php ไฟล์เดียว และ newdetail1.php - newdetail3.php ให้กลายเป็น newdetail.php ไฟล์เดียว (ด้วยหลักการดึง value จาก option tag ในไฟล์ testmergefileyear1.php เพื่อให้สา |
|
|
|
|
|
|
|
สอบถามว่า ต้องเขียน Code อย่างไร จึงจะรวมไฟล์ excel1.php - excel3.php ให้กลายเป็นไฟล์ excel.php ไฟล์เดียว และ newdetail1.php - newdetail3.php ให้กลายเป็น newdetail.php ไฟล์เดียว (ด้วยหลักการดึง value จาก option tag ในไฟล์ testmergefileyear1.php เพื่อให้สามารถโหลดไฟล์ excel จาก excel.php หรือเข้าไปดู newdetail จาก newdetail.php ตาม value ที่เลือกจาก option tag ในไฟล์ testmergefileyear1.php) ได้ครับ
โครงสร้างของไฟล์ทั้งหมดครับ
testmergefile
├── classes
│ └── thai.php
├── newiframe
│ ├── excel1.php
│ ├── excel2.php
│ ├── excel3.php
│ ├── newdetail1.php
│ ├── newdetail2.php
│ └── newdetail3.php
├── index.php
└── testmergefileyear1.php
รูปภาพอธิบายคำถามครับ - https://i.ibb.co/FmVFj3N/000006-combine-file-excel-php-code-to-one.png
ตัวอย่าง Code ทั้งหมดครับ
1. testmerge1.sql
-- phpMyAdmin SQL Dump
-- version 5.2.0
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Dec 13, 2022 at 06:04 AM
-- Server version: 10.4.25-MariaDB
-- PHP Version: 7.4.30
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `testmerge1`
--
-- --------------------------------------------------------
--
-- Table structure for table `testmerge1`
--
CREATE TABLE `testmerge1` (
`UserID` int(255) UNSIGNED ZEROFILL NOT NULL,
`carlist` longtext COLLATE utf8_unicode_ci NOT NULL,
`ddmmyy` longtext COLLATE utf8_unicode_ci NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `testmerge1`
--
INSERT INTO `testmerge1` (`UserID`, `carlist`, `ddmmyy`) VALUES
(000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001, '2001', '20-01-2562'),
(000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002, '3001', '20-02-2562'),
(000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003, '4001', '20-03-2562');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `testmerge1`
--
ALTER TABLE `testmerge1`
ADD PRIMARY KEY (`UserID`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `testmerge1`
--
ALTER TABLE `testmerge1`
MODIFY `UserID` int(255) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
2. thai.php
<?php
namespace classes;
use \DateTime as DateTime;
class thai {
/*==================Datetime=====================*/
public static function date_format(DateTime $date, $format) {
$thaidate = array(
'Sun' => array('l' => 'อาทิตย์', 'D' => 'อา.'),
'Mon' => array('l' => 'จันทร์', 'D' => 'จ.'),
'Tue' => array('l' => 'อังคาร', 'D' => 'อ.'),
'Wed' => array('l' => 'พุธ', 'D' => 'พ.'),
'Thu' => array('l' => 'พฤหัสบดี', 'D' => 'พฤ.'),
'Fri' => array('l' => 'ศุกร์', 'D' => 'ศ.'),
'Sat' => array('l' => 'เสาร์', 'D' => 'ส.'),
'Jan' => array('F' => 'มกราคม', 'M' => 'ม.ค.'),
'Feb' => array('F' => 'กุมภาพันธ์', 'M' => 'ก.พ.'),
'Mar' => array('F' => 'มีนาคม', 'M' => 'มี.ค.'),
'Apr' => array('F' => 'เมษายน', 'M' => 'เม.ย.'),
'May' => array('F' => 'พฤษภาคม', 'M' => 'พ.ค.'),
'Jun' => array('F' => 'มิถุนายน', 'M' => 'มิ.ย.'),
'Jul' => array('F' => 'กรกฎาคม', 'M' => 'ก.ค.'),
'Aug' => array('F' => 'สิงหาคม', 'M' => 'ส.ค.'),
'Sep' => array('F' => 'กันยายน', 'M' => 'ก.ย.'),
'Oct' => array('F' => 'ตุลาคม', 'M' => 'ต.ค.'),
'Nov' => array('F' => 'พฤศจิกายน', 'M' => 'พ.ย.'),
'Dec' => array('F' => 'ธันวาคม', 'M' => 'ธ.ค.'));
$chrarray = str_split($format);
$keys = 'roYyFMlD';
$previous = '';
$newformat = array();
foreach ($chrarray as $chr) {
$match = strpos($keys, $chr);
if ($match !== FALSE && $previous !== '\\') {
$default = $date->format($chr);
switch ($chr) {
case 'r':
$year = strval(intval($date->format('Y')) + 543);
$thai = "{$thaidate[$date->format('D')]['D']} d {$thaidate[$date->format('M')]['M']} $year H:i:s O";
array_push($newformat, $thai);
break;
case 'o':
case 'Y':
$thai = strval(intval($default) + 543);
array_push($newformat, $thai);
break;
case 'y':
$thai = substr(strval(intval($default) + 543), -2);
array_push($newformat, $thai);
break;
default:
$thai = $thaidate[substr($default, 0, 3)][$chr];
array_push($newformat, $thai);
break;
}
$previous = $chr;
}
else {
array_push($newformat, $chr);
$previous = $chr;
}
}
return self::thainum($date->format(implode($newformat)));
}
private static function thainum($string) {
$chrarray = str_split($string);
$num = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$thai = array();
foreach ($chrarray as $chr) {
array_push($thai, (is_numeric($chr)) ? $num[intval($chr)] : $chr);
}
return implode($thai);
}
/*==================Number=====================*/
public static function number($number) {
if (!is_numeric($number)) {
return 'Cann\'t convert.';
}
return self::thainum($number);
}
public static function number_format($number, $decimals = 0, $dec_point = '.', $thousands_sep = ',') {
if (!is_numeric($number)) {
return 'Cann\'t convert.';
}
return self::thainum(number_format($number, $decimals, $dec_point, $thousands_sep));
}
public static function number_totext($number) {
if (!is_numeric($number)) {
return 'Cann\'t convert.';
}
$num = explode('.', strval($number));
$numtext = self::numtotext($num[0]);
$dectext = (count($num) > 1) ? self::dectotext($num[1]) : '';
return (count($num) == 1) ? $numtext : "{$numtext}จุด{$dectext}";
}
public static function number_tobaht($number) {
if (!is_numeric($number)) {
return 'Cann\'t convert.';
}
$num = explode('.', strval($number));
$numtext = self::numtotext($num[0]);
$dectext = (count($num) > 1) ? (strlen($num[1]) <= 2) ? 'บาท' . self::numtotext((strlen($num[1]) == 1) ? $num[1] . '0' : $num[1]) . 'สตางค์' : 'จุด' . self::dectotext($num[1]) . 'บาท' : '';
return (count($num) > 1) ? "{$numtext}{$dectext}" : "{$numtext}บาทถ้วน";
}
private static function numtotext($string) {
$num = self::splitstr($string, 6);
$loop = count($num);
$thai = array();
for ($i = 0; $i < $loop; $i++) {
$numthai = self::numtothai($num[$i]);
for ($m = 0; $m < $i; $m++) {
$numthai .= 'ล้าน';
}
array_push($thai, $numthai);
}
return implode(array_reverse($thai));
}
private static function numtothai($string) {
$len = strlen($string);
$chrarray = array_reverse(str_split($string));
$pos = array('', 'สิบ', 'ร้อย', 'พัน', 'หมื่น', 'แสน');
$num = array('ศูนย์', 'หนึ่ง', 'สอง', 'สาม', 'สี่', 'ห้า', 'หก', 'เจ็ด', 'แปด', 'เก้า');
$thai = array();
for ($i = 0; $i < $len; $i++) {
if ($chrarray[$i] != '0') {
if ($chrarray[$i] == '1' && $i == 0) {
array_push($thai, ($len > 1) ? 'เอ็ด' : 'หนึ่ง' . $pos[$i]);
}
else if ($chrarray[$i] == '1' && $i == 1) {
array_push($thai, $pos[$i]);
}
else if ($chrarray[$i] == '2' && $i == 1) {
array_push($thai, 'ยี่' . $pos[$i]);
}
else {
array_push($thai, $num[intval($chrarray[$i])] . $pos[$i]);
}
}
}
return implode(array_reverse($thai));
}
private static function dectotext($string) {
$chrarray = str_split($string);
$num = array('ศูนย์', 'หนึ่ง', 'สอง', 'สาม', 'สี่', 'ห้า', 'หก', 'เจ็ด', 'แปด', 'เก้า');
$thai = array();
foreach ($chrarray as $chr) {
array_push($thai, (is_numeric($chr)) ? $num[intval($chr)] : $chr);
}
return implode($thai);
}
private static function splitstr($string, $length) {
$len = strlen($string);
$floor = floor($len / $length);
$mod = $len % $length;
$result = array();
if ($floor > 0) {
for($i = 0; $i < $floor; $i++) {
array_push($result, substr($string, 0 - $length * ($i + 1), $length));
}
}
if ($mod > 0) {
array_push($result, substr($string, 0, $mod));
}
return $result;
}
}
?>
3. excel1.php
<?php
//คำสั่ง connect db เขียนเพิ่มเองนะ
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "testmerge1";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
mysqli_set_charset($conn,"utf8");
$strExcelFileName="Test Merge.xls";
header("Content-Type: application/x-msexcel; name=\"$strExcelFileName\"");
header("Content-Disposition: inline; filename=\"$strExcelFileName\"");
header("Pragma:no-cache");
$sql = "SELECT * FROM testmerge1 WHERE ddmmyy LIKE '%-01-2562' ";
$query = mysqli_query($conn,$sql);
?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<strong>ตาราง Test Merge</strong><br>
<br>
<div id="SiXhEaD_Excel" align=center x:publishsource="Excel">
<table x:str border=1 cellpadding=0 cellspacing=1 width=100% style="border-collapse:collapse">
<tr>
<th width="91"> <div align="center">ข้อมูลรถ </div></th>
<th width="91"> <div align="center">วันที่เข้ามารับ </div></th>
</tr>
<?php
while($result=mysqli_fetch_array($query,MYSQLI_ASSOC))
{
?>
<tr>
<td><div align="center"><?php echo $result["carlist"];?></div></td>
<td><div align="center"><?php echo $result["ddmmyy"];?></div></td>
</tr>
<?php
}
?>
</table>
</div>
<script>
window.onbeforeunload = function(){return false;};
setTimeout(function(){window.close();}, 10000);
</script>
</body>
</html>
4. excel2.php
<?php
//คำสั่ง connect db เขียนเพิ่มเองนะ
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "testmerge1";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
mysqli_set_charset($conn,"utf8");
$strExcelFileName="Test Merge.xls";
header("Content-Type: application/x-msexcel; name=\"$strExcelFileName\"");
header("Content-Disposition: inline; filename=\"$strExcelFileName\"");
header("Pragma:no-cache");
$sql = "SELECT * FROM testmerge1 WHERE ddmmyy LIKE '%-02-2562' ";
$query = mysqli_query($conn,$sql);
?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<strong>ตาราง Test Merge</strong><br>
<br>
<div id="SiXhEaD_Excel" align=center x:publishsource="Excel">
<table x:str border=1 cellpadding=0 cellspacing=1 width=100% style="border-collapse:collapse">
<tr>
<th width="91"> <div align="center">ข้อมูลรถ </div></th>
<th width="91"> <div align="center">วันที่เข้ามารับ </div></th>
</tr>
<?php
while($result=mysqli_fetch_array($query,MYSQLI_ASSOC))
{
?>
<tr>
<td><div align="center"><?php echo $result["carlist"];?></div></td>
<td><div align="center"><?php echo $result["ddmmyy"];?></div></td>
</tr>
<?php
}
?>
</table>
</div>
<script>
window.onbeforeunload = function(){return false;};
setTimeout(function(){window.close();}, 10000);
</script>
</body>
</html>
5. excel3.php
<?php
//คำสั่ง connect db เขียนเพิ่มเองนะ
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "testmerge1";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
mysqli_set_charset($conn,"utf8");
$strExcelFileName="Test Merge.xls";
header("Content-Type: application/x-msexcel; name=\"$strExcelFileName\"");
header("Content-Disposition: inline; filename=\"$strExcelFileName\"");
header("Pragma:no-cache");
$sql = "SELECT * FROM testmerge1 WHERE ddmmyy LIKE '%-03-2562' ";
$query = mysqli_query($conn,$sql);
?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<strong>ตาราง Test Merge</strong><br>
<br>
<div id="SiXhEaD_Excel" align=center x:publishsource="Excel">
<table x:str border=1 cellpadding=0 cellspacing=1 width=100% style="border-collapse:collapse">
<tr>
<th width="91"> <div align="center">ข้อมูลรถ </div></th>
<th width="91"> <div align="center">วันที่เข้ามารับ </div></th>
</tr>
<?php
while($result=mysqli_fetch_array($query,MYSQLI_ASSOC))
{
?>
<tr>
<td><div align="center"><?php echo $result["carlist"];?></div></td>
<td><div align="center"><?php echo $result["ddmmyy"];?></div></td>
</tr>
<?php
}
?>
</table>
</div>
<script>
window.onbeforeunload = function(){return false;};
setTimeout(function(){window.close();}, 10000);
</script>
</body>
</html>
6. newdetail1.php
<html>
<head>
<meta charset="UTF-8">
<style>
table.one {
border-style: solid;
border-width: 3px;
border-color:#713788;
font-size: 12px;
background-color: lightgrey;
}
table.two {
font-size: 18px;
}
table {
border: none;
}
td.status {
color: green;
}
a.edit {
background-color:#713788;
color: white;
text-decoration: none;
}
</style>
</head>
<body>
<?php
ini_set('display_errors', 0);
error_reporting(~0);
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "testmerge1";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
mysqli_set_charset($conn,"utf8");
$sql2 = "SELECT * FROM testmerge1 WHERE ddmmyy LIKE '%-01-2562' ";
$query2 = mysqli_query($conn,$sql2);
?>
<table class="two" border="0">
<tr>
<th><div align="center"><a href="/testmergefile/index.php">Back Page</a></div></th>
</tr>
</table>
<table class="two" border="0">
<tr>
<th><div align="center"><a href="excel1.php" target="_blank">Export to Excel</a></div></th>
</tr>
</table>
<br/>
<table class="one" width="600" border="1">
<tr>
<th width="91"> <div align="center">ข้อมูลรถ </div></th>
<th width="91"> <div align="center">วันที่เข้ามารับ </div></th>
</tr>
<?php
while($result=mysqli_fetch_array($query2,MYSQLI_ASSOC))
{
?>
<tr>
<td><div align="center"><?php echo $result["carlist"];?></div></td>
<td><div align="center"><?php echo $result["ddmmyy"];?></div></td>
</tr>
<?php
}
?>
</table>
<?php
mysqli_close($conn);
?>
</body>
</html>
7. newdetail2.php
<html>
<head>
<meta charset="UTF-8">
<style>
table.one {
border-style: solid;
border-width: 3px;
border-color:#713788;
font-size: 12px;
background-color: lightgrey;
}
table.two {
font-size: 18px;
}
table {
border: none;
}
td.status {
color: green;
}
a.edit {
background-color:#713788;
color: white;
text-decoration: none;
}
</style>
</head>
<body>
<?php
ini_set('display_errors', 0);
error_reporting(~0);
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "testmerge1";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
mysqli_set_charset($conn,"utf8");
$sql2 = "SELECT * FROM testmerge1 WHERE ddmmyy LIKE '%-02-2562' ";
$query2 = mysqli_query($conn,$sql2);
?>
<table class="two" border="0">
<tr>
<th><div align="center"><a href="/testmergefile/index.php">Back Page</a></div></th>
</tr>
</table>
<table class="two" border="0">
<tr>
<th><div align="center"><a href="excel2.php" target="_blank">Export to Excel</a></div></th>
</tr>
</table>
<br/>
<table class="one" width="600" border="1">
<tr>
<th width="91"> <div align="center">ข้อมูลรถ </div></th>
<th width="91"> <div align="center">วันที่เข้ามารับ </div></th>
</tr>
<?php
while($result=mysqli_fetch_array($query2,MYSQLI_ASSOC))
{
?>
<tr>
<td><div align="center"><?php echo $result["carlist"];?></div></td>
<td><div align="center"><?php echo $result["ddmmyy"];?></div></td>
</tr>
<?php
}
?>
</table>
<?php
mysqli_close($conn);
?>
</body>
</html>
8. newdetail3.php
<html>
<head>
<meta charset="UTF-8">
<style>
table.one {
border-style: solid;
border-width: 3px;
border-color:#713788;
font-size: 12px;
background-color: lightgrey;
}
table.two {
font-size: 18px;
}
table {
border: none;
}
td.status {
color: green;
}
a.edit {
background-color:#713788;
color: white;
text-decoration: none;
}
</style>
</head>
<body>
<?php
ini_set('display_errors', 0);
error_reporting(~0);
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "testmerge1";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
mysqli_set_charset($conn,"utf8");
$sql2 = "SELECT * FROM testmerge1 WHERE ddmmyy LIKE '%-03-2562' ";
$query2 = mysqli_query($conn,$sql2);
?>
<table class="two" border="0">
<tr>
<th><div align="center"><a href="/testmergefile/index.php">Back Page</a></div></th>
</tr>
</table>
<table class="two" border="0">
<tr>
<th><div align="center"><a href="excel3.php" target="_blank">Export to Excel</a></div></th>
</tr>
</table>
<br/>
<table class="one" width="600" border="1">
<tr>
<th width="91"> <div align="center">ข้อมูลรถ </div></th>
<th width="91"> <div align="center">วันที่เข้ามารับ </div></th>
</tr>
<?php
while($result=mysqli_fetch_array($query2,MYSQLI_ASSOC))
{
?>
<tr>
<td><div align="center"><?php echo $result["carlist"];?></div></td>
<td><div align="center"><?php echo $result["ddmmyy"];?></div></td>
</tr>
<?php
}
?>
</table>
<?php
mysqli_close($conn);
?>
</body>
</html>
9. index.php
<?php
spl_autoload_extensions('.php');
spl_autoload_register();
use classes\thai as thai;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
/* Full-width input fields */
input[type=text], input[type=password], input[type=time], select, textarea {
font-size: 20px;
}
table.two {
font-size: 18px;
}
table {
border: none;
}
td.status {
color: green;
}
a.edit {
background-color:#713788;
color: white;
text-decoration: none;
}
</style>
</head>
<body>
<table class="two" border="0">
<tr>
<th><div align="center">Summary Month</div></th>
</tr>
</table>
<?php
$begin = new DateTime('2019-01-01');
$end = new DateTime('2020-01-01');
$interval = DateInterval::createFromDateString('12 month');
$period = new DatePeriod($begin, $interval, $end);
$y = "testmergefileyear";
$x = 1;
?>
<br>
<select name="carlist" form="carform" onchange="location = this.value;">
<option>Select Year ...</option>
<?php
foreach ($period as $dt) {
echo "<option value='". $y . $x++ . ".php" ."'>".$z.thai::date_format($dt, 'Y')."";
echo "</option>";
}
?>
</select>
</body>
</html>
10. testmergefileyear1.php
<?php
spl_autoload_extensions('.php');
spl_autoload_register();
use classes\thai as thai;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
/* Full-width input fields */
input[type=text], input[type=password], input[type=time], select, textarea {
font-size: 20px;
}
table.two {
font-size: 18px;
}
table {
border: none;
}
td.status {
color: green;
}
a.edit {
background-color:#713788;
color: white;
text-decoration: none;
}
button {
background-color: #713788;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
}
</style>
</head>
<body>
<table class="two" border="0">
<tr>
<th><div align="center">สรุปข้อมูล ประจำเดือน</div></th>
</tr>
</table>
<?php
$begin = new DateTime('2019-01-01');
$end = new DateTime('2019-04-01');
$interval = DateInterval::createFromDateString('1 month');
$period = new DatePeriod($begin, $interval, $end);
$y = "newiframe/newdetail";
$x = 1;
?>
<br>
<select name="carlist" form="carform" onchange="location = this.value;">
<option>Select Month</option>
<?php
foreach ($period as $dt) {
echo "<option value='". $y . $x++ . ".php" ."'>".thai::date_format($dt, 'F Y')."";
echo "</option>";
}
?>
</select><br><br>
<button type="submit" onclick="window.history.go(-1); return false;"><h1>Back Page</h1></button>
</body>
</html>
Tag : PHP, MySQL, HTML, HTML5, XAMPP, Windows
|
|
|
|
|
|
Date :
2022-12-26 13:40:19 |
By :
doanga2007 |
View :
463 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตอบความคิดเห็นที่ : 1 เขียนโดย : 009 เมื่อวันที่ 2022-12-29 14:28:17
รายละเอียดของการตอบ ::
ขอบคุณครับ สำหรับคำแนะนำ ตอนนี้สามารถแก้ปัญหา Code ได้แล้ว ตามข้อมูลด้านล่างครับ
Link ค้นหาข้อมูลที่ทำให้แก้ปัญหา Code ได้ - https://stackoverflow.com/questions/42221340/how-to-increment-a-value-with-leading-zeroes-using-php
https://www.w3schools.com/php/php_superglobals_get.asp
โครงสร้างของไฟล์ทั้งหมดครับ
testmergefile
├── classes
│ └── thai.php
├── newiframe
│ ├── excel1.php
│ ├── excel2.php
│ ├── excel3.php
│ ├── newdetail.php
├── index.php
└── testmergefileyear1.php
ตัวอย่าง Code ทั้งหมดครับ
1. testmerge1.sql
-- phpMyAdmin SQL Dump
-- version 5.2.0
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Dec 13, 2022 at 06:04 AM
-- Server version: 10.4.25-MariaDB
-- PHP Version: 7.4.30
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `testmerge1`
--
-- --------------------------------------------------------
--
-- Table structure for table `testmerge1`
--
CREATE TABLE `testmerge1` (
`UserID` int(255) UNSIGNED ZEROFILL NOT NULL,
`carlist` longtext COLLATE utf8_unicode_ci NOT NULL,
`ddmmyy` longtext COLLATE utf8_unicode_ci NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `testmerge1`
--
INSERT INTO `testmerge1` (`UserID`, `carlist`, `ddmmyy`) VALUES
(000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001, '2001', '20-01-2562'),
(000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002, '3001', '20-02-2562'),
(000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003, '4001', '20-03-2562');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `testmerge1`
--
ALTER TABLE `testmerge1`
ADD PRIMARY KEY (`UserID`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `testmerge1`
--
ALTER TABLE `testmerge1`
MODIFY `UserID` int(255) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
2. thai.php
<?php
namespace classes;
use \DateTime as DateTime;
class thai {
/*==================Datetime=====================*/
public static function date_format(DateTime $date, $format) {
$thaidate = array(
'Sun' => array('l' => 'อาทิตย์', 'D' => 'อา.'),
'Mon' => array('l' => 'จันทร์', 'D' => 'จ.'),
'Tue' => array('l' => 'อังคาร', 'D' => 'อ.'),
'Wed' => array('l' => 'พุธ', 'D' => 'พ.'),
'Thu' => array('l' => 'พฤหัสบดี', 'D' => 'พฤ.'),
'Fri' => array('l' => 'ศุกร์', 'D' => 'ศ.'),
'Sat' => array('l' => 'เสาร์', 'D' => 'ส.'),
'Jan' => array('F' => 'มกราคม', 'M' => 'ม.ค.'),
'Feb' => array('F' => 'กุมภาพันธ์', 'M' => 'ก.พ.'),
'Mar' => array('F' => 'มีนาคม', 'M' => 'มี.ค.'),
'Apr' => array('F' => 'เมษายน', 'M' => 'เม.ย.'),
'May' => array('F' => 'พฤษภาคม', 'M' => 'พ.ค.'),
'Jun' => array('F' => 'มิถุนายน', 'M' => 'มิ.ย.'),
'Jul' => array('F' => 'กรกฎาคม', 'M' => 'ก.ค.'),
'Aug' => array('F' => 'สิงหาคม', 'M' => 'ส.ค.'),
'Sep' => array('F' => 'กันยายน', 'M' => 'ก.ย.'),
'Oct' => array('F' => 'ตุลาคม', 'M' => 'ต.ค.'),
'Nov' => array('F' => 'พฤศจิกายน', 'M' => 'พ.ย.'),
'Dec' => array('F' => 'ธันวาคม', 'M' => 'ธ.ค.'));
$chrarray = str_split($format);
$keys = 'roYyFMlD';
$previous = '';
$newformat = array();
foreach ($chrarray as $chr) {
$match = strpos($keys, $chr);
if ($match !== FALSE && $previous !== '\\') {
$default = $date->format($chr);
switch ($chr) {
case 'r':
$year = strval(intval($date->format('Y')) + 543);
$thai = "{$thaidate[$date->format('D')]['D']} d {$thaidate[$date->format('M')]['M']} $year H:i:s O";
array_push($newformat, $thai);
break;
case 'o':
case 'Y':
$thai = strval(intval($default) + 543);
array_push($newformat, $thai);
break;
case 'y':
$thai = substr(strval(intval($default) + 543), -2);
array_push($newformat, $thai);
break;
default:
$thai = $thaidate[substr($default, 0, 3)][$chr];
array_push($newformat, $thai);
break;
}
$previous = $chr;
}
else {
array_push($newformat, $chr);
$previous = $chr;
}
}
return self::thainum($date->format(implode($newformat)));
}
private static function thainum($string) {
$chrarray = str_split($string);
$num = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$thai = array();
foreach ($chrarray as $chr) {
array_push($thai, (is_numeric($chr)) ? $num[intval($chr)] : $chr);
}
return implode($thai);
}
/*==================Number=====================*/
public static function number($number) {
if (!is_numeric($number)) {
return 'Cann\'t convert.';
}
return self::thainum($number);
}
public static function number_format($number, $decimals = 0, $dec_point = '.', $thousands_sep = ',') {
if (!is_numeric($number)) {
return 'Cann\'t convert.';
}
return self::thainum(number_format($number, $decimals, $dec_point, $thousands_sep));
}
public static function number_totext($number) {
if (!is_numeric($number)) {
return 'Cann\'t convert.';
}
$num = explode('.', strval($number));
$numtext = self::numtotext($num[0]);
$dectext = (count($num) > 1) ? self::dectotext($num[1]) : '';
return (count($num) == 1) ? $numtext : "{$numtext}จุด{$dectext}";
}
public static function number_tobaht($number) {
if (!is_numeric($number)) {
return 'Cann\'t convert.';
}
$num = explode('.', strval($number));
$numtext = self::numtotext($num[0]);
$dectext = (count($num) > 1) ? (strlen($num[1]) <= 2) ? 'บาท' . self::numtotext((strlen($num[1]) == 1) ? $num[1] . '0' : $num[1]) . 'สตางค์' : 'จุด' . self::dectotext($num[1]) . 'บาท' : '';
return (count($num) > 1) ? "{$numtext}{$dectext}" : "{$numtext}บาทถ้วน";
}
private static function numtotext($string) {
$num = self::splitstr($string, 6);
$loop = count($num);
$thai = array();
for ($i = 0; $i < $loop; $i++) {
$numthai = self::numtothai($num[$i]);
for ($m = 0; $m < $i; $m++) {
$numthai .= 'ล้าน';
}
array_push($thai, $numthai);
}
return implode(array_reverse($thai));
}
private static function numtothai($string) {
$len = strlen($string);
$chrarray = array_reverse(str_split($string));
$pos = array('', 'สิบ', 'ร้อย', 'พัน', 'หมื่น', 'แสน');
$num = array('ศูนย์', 'หนึ่ง', 'สอง', 'สาม', 'สี่', 'ห้า', 'หก', 'เจ็ด', 'แปด', 'เก้า');
$thai = array();
for ($i = 0; $i < $len; $i++) {
if ($chrarray[$i] != '0') {
if ($chrarray[$i] == '1' && $i == 0) {
array_push($thai, ($len > 1) ? 'เอ็ด' : 'หนึ่ง' . $pos[$i]);
}
else if ($chrarray[$i] == '1' && $i == 1) {
array_push($thai, $pos[$i]);
}
else if ($chrarray[$i] == '2' && $i == 1) {
array_push($thai, 'ยี่' . $pos[$i]);
}
else {
array_push($thai, $num[intval($chrarray[$i])] . $pos[$i]);
}
}
}
return implode(array_reverse($thai));
}
private static function dectotext($string) {
$chrarray = str_split($string);
$num = array('ศูนย์', 'หนึ่ง', 'สอง', 'สาม', 'สี่', 'ห้า', 'หก', 'เจ็ด', 'แปด', 'เก้า');
$thai = array();
foreach ($chrarray as $chr) {
array_push($thai, (is_numeric($chr)) ? $num[intval($chr)] : $chr);
}
return implode($thai);
}
private static function splitstr($string, $length) {
$len = strlen($string);
$floor = floor($len / $length);
$mod = $len % $length;
$result = array();
if ($floor > 0) {
for($i = 0; $i < $floor; $i++) {
array_push($result, substr($string, 0 - $length * ($i + 1), $length));
}
}
if ($mod > 0) {
array_push($result, substr($string, 0, $mod));
}
return $result;
}
}
?>
3. excel1.php
<?php
//คำสั่ง connect db เขียนเพิ่มเองนะ
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "testmerge1";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
mysqli_set_charset($conn,"utf8");
$strExcelFileName="Test Merge.xls";
header("Content-Type: application/x-msexcel; name=\"$strExcelFileName\"");
header("Content-Disposition: inline; filename=\"$strExcelFileName\"");
header("Pragma:no-cache");
$sql = "SELECT * FROM testmerge1 WHERE ddmmyy LIKE '%-01-2562' ";
$query = mysqli_query($conn,$sql);
?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<strong>ตาราง Test Merge</strong><br>
<br>
<div id="SiXhEaD_Excel" align=center x:publishsource="Excel">
<table x:str border=1 cellpadding=0 cellspacing=1 width=100% style="border-collapse:collapse">
<tr>
<th width="91"> <div align="center">ข้อมูลรถ </div></th>
<th width="91"> <div align="center">วันที่เข้ามารับ </div></th>
</tr>
<?php
while($result=mysqli_fetch_array($query,MYSQLI_ASSOC))
{
?>
<tr>
<td><div align="center"><?php echo $result["carlist"];?></div></td>
<td><div align="center"><?php echo $result["ddmmyy"];?></div></td>
</tr>
<?php
}
?>
</table>
</div>
<script>
window.onbeforeunload = function(){return false;};
setTimeout(function(){window.close();}, 10000);
</script>
</body>
</html>
4. excel2.php
<?php
//คำสั่ง connect db เขียนเพิ่มเองนะ
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "testmerge1";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
mysqli_set_charset($conn,"utf8");
$strExcelFileName="Test Merge.xls";
header("Content-Type: application/x-msexcel; name=\"$strExcelFileName\"");
header("Content-Disposition: inline; filename=\"$strExcelFileName\"");
header("Pragma:no-cache");
$sql = "SELECT * FROM testmerge1 WHERE ddmmyy LIKE '%-02-2562' ";
$query = mysqli_query($conn,$sql);
?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<strong>ตาราง Test Merge</strong><br>
<br>
<div id="SiXhEaD_Excel" align=center x:publishsource="Excel">
<table x:str border=1 cellpadding=0 cellspacing=1 width=100% style="border-collapse:collapse">
<tr>
<th width="91"> <div align="center">ข้อมูลรถ </div></th>
<th width="91"> <div align="center">วันที่เข้ามารับ </div></th>
</tr>
<?php
while($result=mysqli_fetch_array($query,MYSQLI_ASSOC))
{
?>
<tr>
<td><div align="center"><?php echo $result["carlist"];?></div></td>
<td><div align="center"><?php echo $result["ddmmyy"];?></div></td>
</tr>
<?php
}
?>
</table>
</div>
<script>
window.onbeforeunload = function(){return false;};
setTimeout(function(){window.close();}, 10000);
</script>
</body>
</html>
5. excel3.php
<?php
//คำสั่ง connect db เขียนเพิ่มเองนะ
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "testmerge1";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
mysqli_set_charset($conn,"utf8");
$strExcelFileName="Test Merge.xls";
header("Content-Type: application/x-msexcel; name=\"$strExcelFileName\"");
header("Content-Disposition: inline; filename=\"$strExcelFileName\"");
header("Pragma:no-cache");
$sql = "SELECT * FROM testmerge1 WHERE ddmmyy LIKE '%-03-2562' ";
$query = mysqli_query($conn,$sql);
?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<strong>ตาราง Test Merge</strong><br>
<br>
<div id="SiXhEaD_Excel" align=center x:publishsource="Excel">
<table x:str border=1 cellpadding=0 cellspacing=1 width=100% style="border-collapse:collapse">
<tr>
<th width="91"> <div align="center">ข้อมูลรถ </div></th>
<th width="91"> <div align="center">วันที่เข้ามารับ </div></th>
</tr>
<?php
while($result=mysqli_fetch_array($query,MYSQLI_ASSOC))
{
?>
<tr>
<td><div align="center"><?php echo $result["carlist"];?></div></td>
<td><div align="center"><?php echo $result["ddmmyy"];?></div></td>
</tr>
<?php
}
?>
</table>
</div>
<script>
window.onbeforeunload = function(){return false;};
setTimeout(function(){window.close();}, 10000);
</script>
</body>
</html>
6. newdetail.php
<html>
<head>
<meta charset="UTF-8">
<style>
table.one {
border-style: solid;
border-width: 3px;
border-color:#713788;
font-size: 12px;
background-color: lightgrey;
}
table.two {
font-size: 18px;
}
table {
border: none;
}
td.status {
color: green;
}
a.edit {
background-color:#713788;
color: white;
text-decoration: none;
}
</style>
</head>
<body>
<?php
ini_set('display_errors', 0);
error_reporting(~0);
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "testmerge1";
$_month = $_GET['month'];
$_month = "%-".$_month;
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
mysqli_set_charset($conn,"utf8");
$sql2 = "SELECT * FROM testmerge1 WHERE ddmmyy LIKE '".$_month."' ";
$query2 = mysqli_query($conn,$sql2);
?>
<table class="two" border="0">
<tr>
<th><div align="center"><a href="/testmergefile/index.php">Back Page</a></div></th>
</tr>
</table>
<?php
if ($_month == "%-01-2562") {
echo '<table class="two" border="0"><tr>';
echo '<th><div align="center"><a href="excel1.php" target="_blank">Export to Excel</a></div></th>';
echo '</tr></table>';
} else if ($_month == "%-02-2562") {
echo '<table class="two" border="0"><tr>';
echo '<th><div align="center"><a href="excel2.php" target="_blank">Export to Excel</a></div></th>';
echo '</tr></table>';
} else if ($_month == "%-03-2562") {
echo '<table class="two" border="0"><tr>';
echo '<th><div align="center"><a href="excel3.php" target="_blank">Export to Excel</a></div></th>';
echo '</tr></table>';
} else {
echo '<table class="two" border="0"><tr>';
echo '<th><div align="center"><a href="excel1.php" target="_blank">Export to Excel</a></div></th>';
echo '</tr></table>';
}
?>
<br/>
<table class="one" width="600" border="1">
<tr>
<th width="91"> <div align="center">ข้อมูลรถ </div></th>
<th width="91"> <div align="center">วันที่เข้ามารับ </div></th>
</tr>
<?php
while($result=mysqli_fetch_array($query2,MYSQLI_ASSOC))
{
?>
<tr>
<td><div align="center"><?php echo $result["carlist"];?></div></td>
<td><div align="center"><?php echo $result["ddmmyy"];?></div></td>
</tr>
<?php
}
?>
</table>
<?php
mysqli_close($conn);
?>
</body>
</html>
7. index.php
<?php
spl_autoload_extensions('.php');
spl_autoload_register();
use classes\thai as thai;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
/* Full-width input fields */
input[type=text], input[type=password], input[type=time], select, textarea {
font-size: 20px;
}
table.two {
font-size: 18px;
}
table {
border: none;
}
td.status {
color: green;
}
a.edit {
background-color:#713788;
color: white;
text-decoration: none;
}
</style>
</head>
<body>
<table class="two" border="0">
<tr>
<th><div align="center">Summary Month</div></th>
</tr>
</table>
<?php
$begin = new DateTime('2019-01-01');
$end = new DateTime('2020-01-01');
$interval = DateInterval::createFromDateString('12 month');
$period = new DatePeriod($begin, $interval, $end);
$y = "testmergefileyear";
$x = 1;
?>
<br>
<select name="carlist" form="carform" onchange="location = this.value;">
<option value="index.php">Select Year ...</option>
<?php
foreach ($period as $dt) {
echo "<option value='". $y . $x++ . ".php" ."'>".$z.thai::date_format($dt, 'Y')."";
echo "</option>";
}
?>
</select>
</body>
</html>
8. testmergefileyear1.php
<?php
spl_autoload_extensions('.php');
spl_autoload_register();
use classes\thai as thai;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
/* Full-width input fields */
input[type=text], input[type=password], input[type=time], select, textarea {
font-size: 20px;
}
table.one {
border-style: solid;
border-width: 3px;
border-color:#713788;
font-size: 12px;
background-color: lightgrey;
}
table.two {
font-size: 18px;
}
table {
border: none;
}
td.status {
color: green;
}
a.edit {
background-color:#713788;
color: white;
text-decoration: none;
}
button {
background-color: #713788;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
}
</style>
</head>
<body>
<table class="two" border="0">
<tr>
<th><div align="center">สรุปข้อมูล ประจำเดือน</div></th>
</tr>
</table>
<?php
ini_set('display_errors', 0);
error_reporting(~0);
$begin = new DateTime('2019-01-01');
$end = new DateTime('2019-04-01');
$interval = DateInterval::createFromDateString('1 month');
$period = new DatePeriod($begin, $interval, $end);
$z = "?month=";
$y = "newiframe/newdetail";
$x = 1;
$w = "-2562";
?>
<br>
<select name="carlist" form="carform" onchange="location = this.value;">
<option value="testmergefileyear1.php">Select Month</option>
<?php
foreach ($period as $dt) {
echo "<option value='". $y . ".php" . $z . str_pad($x++,2,"0",STR_PAD_LEFT) . $w ."'>".thai::date_format($dt, 'F Y')."";
echo "</option>";
}
?>
</select><br><br>
<button type="submit" onclick="window.history.go(-1); return false;"><h1>Back Page</h1></button>
</body>
</html>
|
ประวัติการแก้ไข 2023-01-01 19:20:09
|
|
|
|
Date :
2023-01-01 19:18:34 |
By :
doanga2007 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตอบความคิดเห็นที่ : 2 เขียนโดย : doanga2007 เมื่อวันที่ 2023-01-01 19:18:34
รายละเอียดของการตอบ ::
ทำการ Update Code ซึ่งมีโครงสร้างของไฟล์ทั้งหมด ดังนี้ครับ
testmergefile
├── classes
│ └── thai.php
├── newiframe
│ ├── excel.php
│ ├── newdetail.php
├── index.php
└── testmergefileyear1.php
ตัวอย่าง Code ทั้งหมดครับ
1. testmerge1.sql
-- phpMyAdmin SQL Dump
-- version 5.2.0
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Dec 13, 2022 at 06:04 AM
-- Server version: 10.4.25-MariaDB
-- PHP Version: 7.4.30
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `testmerge1`
--
-- --------------------------------------------------------
--
-- Table structure for table `testmerge1`
--
CREATE TABLE `testmerge1` (
`UserID` int(255) UNSIGNED ZEROFILL NOT NULL,
`carlist` longtext COLLATE utf8_unicode_ci NOT NULL,
`ddmmyy` longtext COLLATE utf8_unicode_ci NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `testmerge1`
--
INSERT INTO `testmerge1` (`UserID`, `carlist`, `ddmmyy`) VALUES
(000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001, '2001', '20-01-2562'),
(000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002, '3001', '20-02-2562'),
(000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003, '4001', '20-03-2562');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `testmerge1`
--
ALTER TABLE `testmerge1`
ADD PRIMARY KEY (`UserID`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `testmerge1`
--
ALTER TABLE `testmerge1`
MODIFY `UserID` int(255) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
2. thai.php
<?php
namespace classes;
use \DateTime as DateTime;
class thai {
/*==================Datetime=====================*/
public static function date_format(DateTime $date, $format) {
$thaidate = array(
'Sun' => array('l' => 'อาทิตย์', 'D' => 'อา.'),
'Mon' => array('l' => 'จันทร์', 'D' => 'จ.'),
'Tue' => array('l' => 'อังคาร', 'D' => 'อ.'),
'Wed' => array('l' => 'พุธ', 'D' => 'พ.'),
'Thu' => array('l' => 'พฤหัสบดี', 'D' => 'พฤ.'),
'Fri' => array('l' => 'ศุกร์', 'D' => 'ศ.'),
'Sat' => array('l' => 'เสาร์', 'D' => 'ส.'),
'Jan' => array('F' => 'มกราคม', 'M' => 'ม.ค.'),
'Feb' => array('F' => 'กุมภาพันธ์', 'M' => 'ก.พ.'),
'Mar' => array('F' => 'มีนาคม', 'M' => 'มี.ค.'),
'Apr' => array('F' => 'เมษายน', 'M' => 'เม.ย.'),
'May' => array('F' => 'พฤษภาคม', 'M' => 'พ.ค.'),
'Jun' => array('F' => 'มิถุนายน', 'M' => 'มิ.ย.'),
'Jul' => array('F' => 'กรกฎาคม', 'M' => 'ก.ค.'),
'Aug' => array('F' => 'สิงหาคม', 'M' => 'ส.ค.'),
'Sep' => array('F' => 'กันยายน', 'M' => 'ก.ย.'),
'Oct' => array('F' => 'ตุลาคม', 'M' => 'ต.ค.'),
'Nov' => array('F' => 'พฤศจิกายน', 'M' => 'พ.ย.'),
'Dec' => array('F' => 'ธันวาคม', 'M' => 'ธ.ค.'));
$chrarray = str_split($format);
$keys = 'roYyFMlD';
$previous = '';
$newformat = array();
foreach ($chrarray as $chr) {
$match = strpos($keys, $chr);
if ($match !== FALSE && $previous !== '\\') {
$default = $date->format($chr);
switch ($chr) {
case 'r':
$year = strval(intval($date->format('Y')) + 543);
$thai = "{$thaidate[$date->format('D')]['D']} d {$thaidate[$date->format('M')]['M']} $year H:i:s O";
array_push($newformat, $thai);
break;
case 'o':
case 'Y':
$thai = strval(intval($default) + 543);
array_push($newformat, $thai);
break;
case 'y':
$thai = substr(strval(intval($default) + 543), -2);
array_push($newformat, $thai);
break;
default:
$thai = $thaidate[substr($default, 0, 3)][$chr];
array_push($newformat, $thai);
break;
}
$previous = $chr;
}
else {
array_push($newformat, $chr);
$previous = $chr;
}
}
return self::thainum($date->format(implode($newformat)));
}
private static function thainum($string) {
$chrarray = str_split($string);
$num = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$thai = array();
foreach ($chrarray as $chr) {
array_push($thai, (is_numeric($chr)) ? $num[intval($chr)] : $chr);
}
return implode($thai);
}
/*==================Number=====================*/
public static function number($number) {
if (!is_numeric($number)) {
return 'Cann\'t convert.';
}
return self::thainum($number);
}
public static function number_format($number, $decimals = 0, $dec_point = '.', $thousands_sep = ',') {
if (!is_numeric($number)) {
return 'Cann\'t convert.';
}
return self::thainum(number_format($number, $decimals, $dec_point, $thousands_sep));
}
public static function number_totext($number) {
if (!is_numeric($number)) {
return 'Cann\'t convert.';
}
$num = explode('.', strval($number));
$numtext = self::numtotext($num[0]);
$dectext = (count($num) > 1) ? self::dectotext($num[1]) : '';
return (count($num) == 1) ? $numtext : "{$numtext}จุด{$dectext}";
}
public static function number_tobaht($number) {
if (!is_numeric($number)) {
return 'Cann\'t convert.';
}
$num = explode('.', strval($number));
$numtext = self::numtotext($num[0]);
$dectext = (count($num) > 1) ? (strlen($num[1]) <= 2) ? 'บาท' . self::numtotext((strlen($num[1]) == 1) ? $num[1] . '0' : $num[1]) . 'สตางค์' : 'จุด' . self::dectotext($num[1]) . 'บาท' : '';
return (count($num) > 1) ? "{$numtext}{$dectext}" : "{$numtext}บาทถ้วน";
}
private static function numtotext($string) {
$num = self::splitstr($string, 6);
$loop = count($num);
$thai = array();
for ($i = 0; $i < $loop; $i++) {
$numthai = self::numtothai($num[$i]);
for ($m = 0; $m < $i; $m++) {
$numthai .= 'ล้าน';
}
array_push($thai, $numthai);
}
return implode(array_reverse($thai));
}
private static function numtothai($string) {
$len = strlen($string);
$chrarray = array_reverse(str_split($string));
$pos = array('', 'สิบ', 'ร้อย', 'พัน', 'หมื่น', 'แสน');
$num = array('ศูนย์', 'หนึ่ง', 'สอง', 'สาม', 'สี่', 'ห้า', 'หก', 'เจ็ด', 'แปด', 'เก้า');
$thai = array();
for ($i = 0; $i < $len; $i++) {
if ($chrarray[$i] != '0') {
if ($chrarray[$i] == '1' && $i == 0) {
array_push($thai, ($len > 1) ? 'เอ็ด' : 'หนึ่ง' . $pos[$i]);
}
else if ($chrarray[$i] == '1' && $i == 1) {
array_push($thai, $pos[$i]);
}
else if ($chrarray[$i] == '2' && $i == 1) {
array_push($thai, 'ยี่' . $pos[$i]);
}
else {
array_push($thai, $num[intval($chrarray[$i])] . $pos[$i]);
}
}
}
return implode(array_reverse($thai));
}
private static function dectotext($string) {
$chrarray = str_split($string);
$num = array('ศูนย์', 'หนึ่ง', 'สอง', 'สาม', 'สี่', 'ห้า', 'หก', 'เจ็ด', 'แปด', 'เก้า');
$thai = array();
foreach ($chrarray as $chr) {
array_push($thai, (is_numeric($chr)) ? $num[intval($chr)] : $chr);
}
return implode($thai);
}
private static function splitstr($string, $length) {
$len = strlen($string);
$floor = floor($len / $length);
$mod = $len % $length;
$result = array();
if ($floor > 0) {
for($i = 0; $i < $floor; $i++) {
array_push($result, substr($string, 0 - $length * ($i + 1), $length));
}
}
if ($mod > 0) {
array_push($result, substr($string, 0, $mod));
}
return $result;
}
}
?>
3. excel.php
<?php
//คำสั่ง connect db เขียนเพิ่มเองนะ
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "testmerge1";
$_month = $_GET['month'];
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
mysqli_set_charset($conn,"utf8");
$sql = "SELECT * FROM testmerge1 WHERE ddmmyy LIKE '".$_month."' ";
$query = mysqli_query($conn,$sql);
$strExcelFileName="Test Merge.xls";
header("Content-Type: application/x-msexcel; name=\"$strExcelFileName\"");
header("Content-Disposition: inline; filename=\"$strExcelFileName\"");
header("Pragma:no-cache");
?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<strong>ตาราง Test Merge</strong><br>
<br>
<div id="SiXhEaD_Excel" align=center x:publishsource="Excel">
<table x:str border=1 cellpadding=0 cellspacing=1 width=100% style="border-collapse:collapse">
<tr>
<th width="91"> <div align="center">ข้อมูลรถ </div></th>
<th width="91"> <div align="center">วันที่เข้ามารับ </div></th>
</tr>
<?php
while($result=mysqli_fetch_array($query,MYSQLI_ASSOC))
{
?>
<tr>
<td><div align="center"><?php echo $result["carlist"];?></div></td>
<td><div align="center"><?php echo $result["ddmmyy"];?></div></td>
</tr>
<?php
}
?>
</table>
</div>
<script>
window.onbeforeunload = function(){return false;};
setTimeout(function(){window.close();}, 10000);
</script>
</body>
</html>
4. newdetail.php
<html>
<head>
<meta charset="UTF-8">
<style>
table.one {
border-style: solid;
border-width: 3px;
border-color:#713788;
font-size: 12px;
background-color: lightgrey;
}
table.two {
font-size: 18px;
}
table {
border: none;
}
td.status {
color: green;
}
a.edit {
background-color:#713788;
color: white;
text-decoration: none;
}
</style>
</head>
<body>
<?php
ini_set('display_errors', 0);
error_reporting(~0);
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "testmerge1";
$_month = $_GET['month'];
$_month = "%-".$_month;
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
mysqli_set_charset($conn,"utf8");
$sql2 = "SELECT * FROM testmerge1 WHERE ddmmyy LIKE '".$_month."' ";
$query2 = mysqli_query($conn,$sql2);
?>
<?php
ini_set('display_errors', 0);
error_reporting(~0);
$z = "?month=";
$y = "excel";
?>
<table class="two" border="0">
<tr>
<th><div align="center"><a href="/testmergefile/index.php">Back Page</a></div></th>
</tr>
</table>
<table class="two" border="0"><tr>
<?php
echo "<th><div align='center'>";
echo '<a href="' . $y . ".php" . $z . $_month . '" target="_blank">'. "Export to Excel" ."";
echo "</a></div></th>";
?>
</tr></table>
<br/>
<table class="one" width="600" border="1">
<tr>
<th width="91"> <div align="center">ข้อมูลรถ </div></th>
<th width="91"> <div align="center">วันที่เข้ามารับ </div></th>
</tr>
<?php
while($result=mysqli_fetch_array($query2,MYSQLI_ASSOC))
{
?>
<tr>
<td><div align="center"><?php echo $result["carlist"];?></div></td>
<td><div align="center"><?php echo $result["ddmmyy"];?></div></td>
</tr>
<?php
}
?>
</table>
<?php
mysqli_close($conn);
?>
</body>
</html>
5. index.php
<?php
spl_autoload_extensions('.php');
spl_autoload_register();
use classes\thai as thai;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
/* Full-width input fields */
input[type=text], input[type=password], input[type=time], select, textarea {
font-size: 20px;
}
table.two {
font-size: 18px;
}
table {
border: none;
}
td.status {
color: green;
}
a.edit {
background-color:#713788;
color: white;
text-decoration: none;
}
</style>
</head>
<body>
<table class="two" border="0">
<tr>
<th><div align="center">Summary Month</div></th>
</tr>
</table>
<?php
$begin = new DateTime('2019-01-01');
$end = new DateTime('2020-01-01');
$interval = DateInterval::createFromDateString('12 month');
$period = new DatePeriod($begin, $interval, $end);
$y = "testmergefileyear";
$x = 1;
?>
<br>
<select name="carlist" form="carform" onchange="location = this.value;">
<option value="index.php">Select Year ...</option>
<?php
foreach ($period as $dt) {
echo "<option value='". $y . $x++ . ".php" ."'>".$z.thai::date_format($dt, 'Y')."";
echo "</option>";
}
?>
</select>
</body>
</html>
6. testmergefileyear1.php
<?php
spl_autoload_extensions('.php');
spl_autoload_register();
use classes\thai as thai;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
/* Full-width input fields */
input[type=text], input[type=password], input[type=time], select, textarea {
font-size: 20px;
}
table.one {
border-style: solid;
border-width: 3px;
border-color:#713788;
font-size: 12px;
background-color: lightgrey;
}
table.two {
font-size: 18px;
}
table {
border: none;
}
td.status {
color: green;
}
a.edit {
background-color:#713788;
color: white;
text-decoration: none;
}
button {
background-color: #713788;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
}
</style>
</head>
<body>
<table class="two" border="0">
<tr>
<th><div align="center">สรุปข้อมูล ประจำเดือน</div></th>
</tr>
</table>
<?php
ini_set('display_errors', 0);
error_reporting(~0);
$begin = new DateTime('2019-01-01');
$end = new DateTime('2019-04-01');
$interval = DateInterval::createFromDateString('1 month');
$period = new DatePeriod($begin, $interval, $end);
$z = "?month=";
$y = "newiframe/newdetail";
$x = 1;
$w = "-2562";
?>
<br>
<select name="carlist" form="carform" onchange="location = this.value;">
<option value="testmergefileyear1.php">Select Month</option>
<?php
foreach ($period as $dt) {
echo "<option value='". $y . ".php" . $z . str_pad($x++,2,"0",STR_PAD_LEFT) . $w ."'>".thai::date_format($dt, 'F Y')."";
echo "</option>";
}
?>
</select><br><br>
<button type="submit" onclick="window.history.go(-1); return false;"><h1>Back Page</h1></button>
</body>
</html>
|
|
|
|
|
Date :
2023-05-08 15:19:07 |
By :
doanga2007 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|