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 > ขอคำแนะนำเรื่องการออกรายงานตามข้อมูลจากวันที่ ถึงวันที่ที่เราเลือกออกมาเป็น PDF ครับ



 

ขอคำแนะนำเรื่องการออกรายงานตามข้อมูลจากวันที่ ถึงวันที่ที่เราเลือกออกมาเป็น PDF ครับ

 



Topic : 122284



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



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




คือ อยากจะให้ข้อมูลรายงานออกตามวันที่ที่เราเป็นคนเลือก เช่น เลือก จากวันที่ 2016-02-27 ถึงวันที่ 2016-04-03
แล้วจะมีข้อมูลออกมาตามนี้

y

แต่ตอนนี้ผมยังทำได้แค่ออกรายงานตามข้อมูลทั้งหมดที่มีอยู่ในฐานข้อมูลที่เราเลือกครับ

b

ตัวอย่างฐานข้อมูลที่ใช่ออกรายงาน

n

จะต้องทำยังไงถึงจะดึงข้อมูลออกรายงานตามวันที่ที่เลือก ออกมาเป็นไฟล์ PDF ได้ครับ

code btween-date-sales.php
Code (PHP)
<?php require_once('Connections/MyConnect.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "owner/Login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_salesset1 = "-1";
if (isset($_POST['dateStart'])) {
  $colname_salesset1 = $_POST['dateStart'];
}
$colname2_salesset1 = "-1";
if (isset($_POST['dateEnd'])) {
  $colname2_salesset1 = $_POST['dateEnd'];
}
mysql_select_db($database_MyConnect, $MyConnect);
$query_salesset1 = sprintf("SELECT * FROM sales WHERE sales_receipt_date >= %s and sales_receipt_date<=%s Order by sales_receipt_date ASC", GetSQLValueString($colname_salesset1, "date"),GetSQLValueString($colname2_salesset1, "date"));
$salesset1 = mysql_query($query_salesset1, $MyConnect) or die(mysql_error());
$row_salesset1 = mysql_fetch_assoc($salesset1);
$totalRows_salesset1 = mysql_num_rows($salesset1);
?>
<!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=utf-8" />
<title>btween</title>
<script src="js/jquery.js" type="text/javascript"></script>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<style type="text/css">
#MenuBar1 {
	font-size: 230%;
	font-family: "Courier New", Courier, monospace;
}
body p {
	font-size: 18px;
	text-align: center;
	color: #000;
}
body h2 {
	text-align: center;
}
</style>
<script src="jquery.ui-1.5.2/jquery-1.2.6.js" type="text/javascript"></script>
<script src="jquery.ui-1.5.2/ui/ui.datepicker.js" type="text/javascript"></script>
<link href="jquery.ui-1.5.2/themes/ui.datepicker.css" rel="stylesheet" type="text/css" />
</head>

<body class='container'> 
<p><img src="shop.jpg" width="1117" height="149" />
</p>
<h3>ร้านเกสร
</h3>
<p>ระบบจัดการฐานข้อมูลสำหรับร้านค้าปลีก</p>

<div class="btn-group">
  <button class="btn"><a href="sales_detail.php">ขายสินค้า</a></button>
</div>

<div class="btn-group">
  <button class="btn"><a href="edit-owner.php">แก้ไขข้อมูลส่วนตัว</a></button>
</div>
<div class="btn-group">
  <button class="btn">ออกรายงาน</button>
  <button class="btn dropdown-toggle" data-toggle="dropdown">
    <span class="caret"></span>
  </button>   
  <ul class="dropdown-menu">
    <li><a href="tcpdf/report.php">รายงานสินค้าคงคลัง</a></li>
    <li><a href="tcpdf/report.php">รายงานการขายสินค้า</a></li>
    <li> รายงานลูกหนี้ค้างชำระ </li>
    <li> รายงานสินค้าขายดี </li>
    <li> รายงานกำไร </li>
    <!-- dropdown menu links -->
  </ul> 
</div>
<div class="btn-group">
  <button class="btn"><a href="owner/Login.php">ออกจากระบบ</a></button>
</div>
<body>
<p>&nbsp;</p>
<form id="form1" name="form1" method="post" action=""> 
  <p>จากวันที่
    <input type="text" size="30" value="Click to show datepicker" name="dateStart" id="jQueryUICalendar1"/>
    ถึงวันที่ 
  <input type="text" size="30" value="Click to show datepicker"  name="dateEnd" id="jQueryUICalendar2"/>
  <input type="submit" name="btnsearch" id="btnsearch" value="search" />
  </p>
  <p>&nbsp; </p>
 <table class="table table-bordered" width="500" border="1" align="center">
    <tr class="success">
      <td>รหัสบิล</td>
      <td>รหัสลูกค้า</td>
      <td>ราคาทั้งหมด</td>
      <td>วันที่ใบเสร็จ</td>
    </tr>
    <?php
	 do { ?>
      <tr>
        <td><?php echo $row_salesset1['sales_id']; ?></td>
        <td><?php echo $row_salesset1['customer_id']; ?></td>
        <td><?php echo $row_salesset1['sales_receipt_sumprice']; ?></td>
        <td><?php echo $row_salesset1['sales_receipt_date']; ?></td>
      </tr>
      <?php } while ($row_salesset1 = mysql_fetch_assoc($salesset1)); ?>
  </table>
<p></p>
<script type="text/javascript">
// BeginWebWidget jQuery_UI_Calendar: jQueryUICalendar2
jQuery("#jQueryUICalendar2").datepicker({dateFormat: 'yy-mm-dd'});

// EndWebWidget jQuery_UI_Calendar: jQueryUICalendar2
</script>
<p></p>
  <script type="text/javascript">
// BeginWebWidget jQuery_UI_Calendar: jQueryUICalendar1
jQuery("#jQueryUICalendar1").datepicker({dateFormat: 'yy-mm-dd'});

// EndWebWidget jQuery_UI_Calendar: jQueryUICalendar1
  </script>
</form>
<p>
  <a href="tcpdf/report2.php">
  <input type="submit" name="btnreport" id="btnreport" value="ออกรายงาน" /></a>
</p>

</body>
</html>
<?php
mysql_free_result($salesset1);
?>


code reportsales.php
Code (PHP)
<?php
session_start();
header("Content-type:text/html; charset=UTF-8");                
header("Cache-Control: no-store, no-cache, must-revalidate");               
header("Cache-Control: post-check=0, pre-check=0", false);    
include("db_connect.php");
?>
<style>
td{
        border:1px dashed #CCC;  
}
</style>

    <table width="994" border="0" cellpadding="1" cellspacing="0" style="width:1100px;">  
    	<tr>
        <td width="64" align="center" bgcolor="#F2F2F2">#</td>
        <td width="170" bgcolor="#F2F2F2">&nbsp;รหัสบิล</td>
        <td width="170" bgcolor="#F2F2F2">&nbsp;รหัสลูกค้า</td>
        <td width="170" bgcolor="#F2F2F2">&nbsp;ราคาทั้งหมด</td>
        <td width="170" bgcolor="#F2F2F2">&nbsp;วันที่ใบเสร็จ</td>
        </tr>
<?php
        $i=1;
        $q="SELECT * FROM  `sales` LIMIT 0 , 30";
        $qr=@mysql_query($q);	
        while($rs=@mysql_fetch_array($qr)){
?>  
  <tr>
    <td align="center"><?=(($e_page*$chk_page)+$i)?></td>
    <td >&nbsp;<?=$rs['sales_id']?></td>
    <td >&nbsp;<?=$rs['customer_id']?></td>
    <td >&nbsp;<?=$rs['sales_receipt_sumprice']?></td>
    <td >&nbsp;<?=$rs['sales_receipt_date']?></td>
  </tr>
<?php $i++; } ?>     
    </table>


code report2.php
Code (PHP)
<?php
// Include the main TCPDF library (search for installation path).
require_once('tcpdf/tcpdf.php');
include("tcpdf/class/class_curl.php");

// การตั้งค่าข้อความ ที่เกี่ยวข้องให้ดูในไฟล์ 
// tcpdf / config /  tcpdf_config.php 

// เริ่มสร้างไฟล์ pdf
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// กำหนดรายละเอียดของไฟล์ pdf
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('ninenik');
$pdf->SetTitle('TCPDF table report');
$pdf->SetSubject('TCPDF ทดสอบ');
$pdf->SetKeywords('TCPDF, PDF, ทดสอบ,ninenik, guide');

// กำหนดข้อความส่วนแสดง header
$pdf->SetHeaderData(
    PDF_HEADER_LOGO, // โลโก้ กำหนดค่าในไฟล์  tcpdf_config.php 
    PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001',
    PDF_HEADER_STRING, // กำหนดเพิ่มเติมในไฟล์  tcpdf_config.php 
    array(0,0,0),  // กำหนดสีของข้อความใน header rgb 
    array(0,0,0)   // กำหนดสีของเส้นคั่นใน header rgb 
);

$pdf->setFooterData(
    array(0,64,0),  // กำหนดสีของข้อความใน footer rgb 
    array(220,44,44)   // กำหนดสีของเส้นคั่นใน footer rgb 
);

// กำหนดฟอนท์ของ header และ footer  กำหนดเพิ่มเติมในไฟล์  tcpdf_config.php 
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// ำหนดฟอนท์ของ monospaced  กำหนดเพิ่มเติมในไฟล์  tcpdf_config.php 
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// กำหนดขอบเขตความห่างจากขอบ  กำหนดเพิ่มเติมในไฟล์  tcpdf_config.php 
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// กำหนดแบ่่งหน้าอัตโนมัติ
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// กำหนดสัดส่วนของรูปภาพ  กำหนดเพิ่มเติมในไฟล์  tcpdf_config.php 
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// อนุญาตให้สามารถกำหนดรุปแบบ ฟอนท์ย่อยเพิมเติมในหน้าใช้งานได้
$pdf->setFontSubsetting(true);

// กำหนด ฟอนท์
$pdf->SetFont('thsarabun', '', 14, '', true);

// เพิ่มหน้า 
$pdf->AddPage();
// เรียกใช้งาน ฟังก์ชั่นดึงข้อมูลไฟล์มาใช้งาน
$html = curl_get("http://localhost/Project_Retailstore/tcpdf/reportsales.php");
 // path ไฟล์ 
// ภ้าทดสอบที่เครื่องก็ใช้ http://localhost/data_html.php

// สร้าง pdf ด้วยคำสั่ง writeHTMLCell()
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);

// แสดงไฟล์ pdf
$pdf->Output('table_report.pdf', 'I');
?>




Tag : PHP, MySQL, HTML/CSS, JavaScript, Ajax, jQuery







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2016-04-03 20:11:19 By : suwidha View : 3957 Reply : 3
 

 

No. 1



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

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

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

ใช้ BETWEEN ครับ

Code
WHERE ColDate BETWEEN '2016-02-27' AND '2016-04-03'







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-04-03 22:26:53 By : mr.win
 


 

No. 2



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



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


ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2016-04-03 22:26:53
รายละเอียดของการตอบ ::
ขอบคุณมากครับ
เอาไปใส่ในหน้า btween-date-sales.php หรือ reportsales.php ครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-04-04 00:48:15 By : suwidha
 

 

No. 3



โพสกระทู้ ( 5,105 )
บทความ ( 4 )

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

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


ก็ลองทดสอบเองสิครับ โค้ดคิวรี่ข้อมูลมันอยู่ตรงไหนล่ะ เอาไปใส่ ใส่ตรงไหนแล้วมันได้ผล ก็ตรงนั้นล่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-04-04 09:21:55 By : apisitp
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขอคำแนะนำเรื่องการออกรายงานตามข้อมูลจากวันที่ ถึงวันที่ที่เราเลือกออกมาเป็น PDF ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 01
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 อัตราราคา คลิกที่นี่