สอบถามการออกรายงาน mpdf ใน php สอบถามเรื่องการออกรายงานของ mpdf ใน php

สำหรับผู้ที่ เริ่มต้น Programming - PHP มีอะไร แนะนำ หรือข้อสงสัยต้องบอร์ด นี้ คนที่มีความรู้ แบ่งปันคนอื่นบ้างนะ ปัญหาการเขียนโปรแกรม แบบ OOP Session Cookies php network

Moderator: mindphp, ผู้ดูแลกระดาน

Prnoom Reerak
PHP Newbie
PHP Newbie
โพสต์: 2
ลงทะเบียนเมื่อ: 12/05/2017 9:54 pm

สอบถามการออกรายงาน mpdf ใน php สอบถามเรื่องการออกรายงานของ mpdf ใน php

โพสต์ที่ยังไม่ได้อ่าน โดย Prnoom Reerak »

อยากจะถามว่า ต้องเขียนโค้ดในรูปที่ 1 ยังไง เพื่อให้แสดงออกมาเหมือนกับรูปภาพที่ 3 เพราะอยากจะแสดงผลเป็นไฟล์ pdf ซึ่งวันที่ที่แสดงนั้น ได้ทำการดึงข้อมูลจากฐานข้อมูลมาค่ะ

รูปที่ 1 โค้ดการออกรายงานเป็น pdf
12-5-2560 21-47-45.jpg
12-5-2560 21-47-45.jpg (35.72 KiB) Viewed 1623 times


รูปที่ 2 การแสดงผลใน pdf
12-5-2560 21-51-44.jpg
12-5-2560 21-51-44.jpg (13.63 KiB) Viewed 1623 times
รูปที่ 3 การแสดงผลในไฟล์ php ปกติ
12-5-2560 21-48-09.jpg
12-5-2560 21-48-09.jpg (17.79 KiB) Viewed 1623 times
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41232
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: สอบถามการออกรายงาน mpdf ใน php

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

ขอ copy โค้ดมา ลงหน่อย ครับ
ได้เขียนต่อจากโค้ดที่มาลง ได้
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
Prnoom Reerak
PHP Newbie
PHP Newbie
โพสต์: 2
ลงทะเบียนเมื่อ: 12/05/2017 9:54 pm

Re: สอบถามการออกรายงาน mpdf ใน php สอบถามเรื่องการออกรายงานของ mpdf ใน php

โพสต์ที่ยังไม่ได้อ่าน โดย Prnoom Reerak »

ตอนนี้อยากให้การแสดงผลของไฟล์ PDF แสดงผลเหมือนกับรูปด้านล่าง ที่ใช้ php ปกติในการแสดงผล จะต้องเขียนโค้ดแสดงข้อมูลในฐานข้อมูลได้ยังไงคะ ที่เป็นในรูปแบบตาราง

โค้ดรูปที่ 1
<?php
@session_start() ;
require_once('../mpdf/mpdf.php');
$mpdf = new mPDF();

$content = '
<style>
body,td,th {
font-family: Garuda;
}

</style>
<div class="container">
<p align=center>
<img src=../img/logomwk.jpg width=95 height=98><br>
<div style=margin-top:10px; align=center><b>แบบคำร้องขอสอบแก้ 0 ร มผ มส <br>
โรงเรียนแม่จันวิทยาคม จังหวัดเชียงราย</b></div>
</p>
</div>';
?>
<?php
$host = "localhost" ; // มักเป็น localhost (สอบถาม Host ที่คุณใช้)
$username = "root" ; // Username ของคุณในการเชื่อมต่อกับฐานข้อมูล
$password = "123456" ; // Password ของคุณในการเชื่อมต่อกับฐานข้อมูล
$db = "dbretest60" ; // ชื่อฐานข้อมูลของคุณ

$connect = mysqli_connect($host,$username,$password,$db);

$sql = "select * from tb_student,tb_retest,tb_resubjects where tb_resubjects.studentID=tb_student.studentID and tb_retest.studentID=tb_student.studentID and tb_resubjects.studentID='$_SESSION[login_true]' ";
$result = mysqli_query($connect,$sql);
$array = mysqli_fetch_array($result);

$studentID = $array['studentID'];
$date_retest=$array['date_retest'];
$prenamestd=$array['prenamestd'];
$firstnamestd=$array['firstnamestd'];
$lastnamestd=$array['lastnamestd'];
$level = $array['level'];
$room = $array['room'];
mysqli_free_result($result);


$mpdf->Bookmark('Start of the document');
$mpdf->WriteHTML($content);
$mpdf->WriteHTML('<br>วันที่ลงทะเบียน&nbsp;' .$date_retest);
//$mpdf->WriteHTML($date_retest);
$mpdf->Output();
?>

โค้ดรูปที่ 3
<table border="0" width="70%" align="center">
<tr>
<td width="20%" colspan="2" align="right">
<strong>วันที่ลงทะเบียน</strong> : <?php echo "$date_retest"; ?>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2" height="25"><strong>เรื่อง</strong> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ขอสอบแก้ตัว</td>
</tr>
<tr>
<td colspan="2" height="25"><strong>เรียน</strong> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; รองผู้อำนวยการฝ่ายวิชาการโรงเรียนแม่จันวิทยาคม</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center" height="30"><strong>ข้าพเจ้า</strong> &nbsp;<?php echo $prenamestd ?><?php echo $firstnamestd ?>&nbsp;&nbsp; <?php echo $lastnamestd ?>&nbsp; <strong>เลขประจำตัวนักเรียน</strong>&nbsp; <?php echo $_SESSION[login_true];?><strong> ชั้น</strong> ม.<?php echo $level?>/<?php echo $room ?></td>
</tr>
<tr>
<td colspan="2">มีความประสงค์ขอสอบแก้ตัวในรายวิชาที่ได้รับผลการเรียน “0 ร มผ มส ” ดังนี้</td>
</tr>
<tr>
<td colspan="2"><table class="table table-condensed ">
<tr>
</tr>
<tr align="center">
<td><strong>ที่</strong></td>
<td><strong>รหัสวิชา</strong></td>
<td><strong>รายวิชา</strong></td>
<td><strong>หน่วยกิต</strong></td>
<td><strong>ครูผู้สอน</strong></td>
</tr>
<?
include("../config.inc.php") ;
$number=1;
$sql="select * from tb_resubjects,tb_retest,tb_student,tb_teacher where tb_teacher.teacherID=tb_resubjects.teacherID and tb_student.studentID=tb_resubjects.studentID and tb_resubjects.studentID=tb_retest.studentID and tb_student.studentID=$_SESSION[login_true] ";
$result = mysqli_query($connect,$sql);
while($r=mysqli_fetch_array($result))
{
$id_subjects=$r['id_subjects'];
$subject_code=$r['subject_code'];
$subject_name=$r['subject_name'];
$unit=$r['unit'];
$teacherID=$r['teacherID'];
$prenameTea=$r['prenameTea'];
$firstnameTea=$r['firstnameTea'];
$lastnameTea=$r['lastnameTea'];

echo "
<tr bgcolor=#FFFFFF>
<td align=center>$number</td>
<td>$subject_code</td>
<td>$subject_name</td>
<td align=center>$unit</td>
<td>$prenameTea$firstnameTea&nbsp;&nbsp;$lastnameTea</td>
</tr>";

$number++;
}
?>

</table></td>
</tr>
<tr>
<td colspan="2"><div style="margin-left: 50px;">จึงเรียนมาเพื่อโปรดพิจารณา</div></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="right">ลงชื่อ...............................................นักเรียน<br><br>
<div style="margin-right: 30px;"> (…………………………………..)</div>
</td>
</tr>
<tr>
<td colspan="2">
<strong> ความเห็นครูผู้สอน </strong><br><br>
1. ................................................................................... ลงชื่อ....................................................<br><br>
2. ................................................................................... ลงชื่อ....................................................<br><br>
3. ................................................................................... ลงชื่อ....................................................<br><br>
4. ................................................................................... ลงชื่อ....................................................<br><br>
5. ................................................................................... ลงชื่อ....................................................<br><br>

</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2">
<strong>ความเห็นของฝ่ายงานวัดผล</strong> [&nbsp;&nbsp;] เห็นควรอนุมัติให้ดำเนินการได้ [&nbsp;&nbsp;] ...........................................................<br><br>
ลงชื่อ…………………………………………………………….……….ครูวัดผล


</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2">
<strong>ความเห็นของรองผู้อำนวยการ ฝ่ายวิชาการ</strong><br /><br />
[&nbsp;&nbsp;] อนุมัติ,แจ้งครูผู้สอนดำเนินการ [&nbsp;&nbsp;] ไม่อนุมัติ </td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="right">
<div style="margin-right: 150px;"><strong>ลงชื่อ </strong></div><br />
<div style="margin-right: 20px;">(.........................) </div>
รองผู้อำนวยการฝ่ายวิชาการ
</td>
</tr>
</table>

รูปการแสดงผล
13-5-2560 16-24-30.jpg
13-5-2560 16-24-30.jpg (108.99 KiB) Viewed 1616 times
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41232
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: สอบถามการออกรายงาน mpdf ใน php สอบถามเรื่องการออกรายงานของ mpdf ใน php

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

เตรียมตัวแปลให้ พร้อมก่อน เอาเข้า

โค้ด: เลือกทั้งหมด

$mpdf->WriteHTML('<br>วันที่ลงทะเบียน&nbsp;' .$date_retest); 
อาจแทนเป็น

โค้ด: เลือกทั้งหมด

$str_to_pdf = '<br/>วันที่ลงทะเบียน ' . $date_retest ;
$mpdf->WriteHTML($str_to_pdf); 
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 100