อยากจะถามว่า ต้องเขียนโค้ดในรูปที่ 1 ยังไง เพื่อให้แสดงออกมาเหมือนกับรูปภาพที่ 3 เพราะอยากจะแสดงผลเป็นไฟล์ pdf ซึ่งวันที่ที่แสดงนั้น ได้ทำการดึงข้อมูลจากฐานข้อมูลมาค่ะ
รูปที่ 1 โค้ดการออกรายงานเป็น pdf
รูปที่ 2 การแสดงผลใน pdf
รูปที่ 3 การแสดงผลในไฟล์ php ปกติ
สอบถามการออกรายงาน mpdf ใน php สอบถามเรื่องการออกรายงานของ mpdf ใน php
Moderator: mindphp, ผู้ดูแลกระดาน
-
- PHP Newbie
- โพสต์: 2
- ลงทะเบียนเมื่อ: 12/05/2017 9:54 pm
- mindphp
- ผู้ดูแลระบบ MindPHP
- โพสต์: 41117
- ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
- ติดต่อ:
Re: สอบถามการออกรายงาน mpdf ใน php
ขอ 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
ติดตาม 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
-
- PHP Newbie
- โพสต์: 2
- ลงทะเบียนเมื่อ: 12/05/2017 9:54 pm
Re: สอบถามการออกรายงาน mpdf ใน php สอบถามเรื่องการออกรายงานของ mpdf ใน php
ตอนนี้อยากให้การแสดงผลของไฟล์ 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>วันที่ลงทะเบียน ' .$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> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" height="25"><strong>เรื่อง</strong> ขอสอบแก้ตัว</td>
</tr>
<tr>
<td colspan="2" height="25"><strong>เรียน</strong> รองผู้อำนวยการฝ่ายวิชาการโรงเรียนแม่จันวิทยาคม</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" align="center" height="30"><strong>ข้าพเจ้า</strong> <?php echo $prenamestd ?><?php echo $firstnamestd ?> <?php echo $lastnamestd ?> <strong>เลขประจำตัวนักเรียน</strong> <?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 $lastnameTea</td>
</tr>";
$number++;
}
?>
</table></td>
</tr>
<tr>
<td colspan="2"><div style="margin-left: 50px;">จึงเรียนมาเพื่อโปรดพิจารณา</div></td>
</tr>
<tr>
<td colspan="2"> </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> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">
<strong>ความเห็นของฝ่ายงานวัดผล</strong> [ ] เห็นควรอนุมัติให้ดำเนินการได้ [ ] ...........................................................<br><br>
ลงชื่อ…………………………………………………………….……….ครูวัดผล
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">
<strong>ความเห็นของรองผู้อำนวยการ ฝ่ายวิชาการ</strong><br /><br />
[ ] อนุมัติ,แจ้งครูผู้สอนดำเนินการ [ ] ไม่อนุมัติ </td>
</tr>
<tr>
<td> </td>
<td> </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>
รูปการแสดงผล
โค้ดรูปที่ 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>วันที่ลงทะเบียน ' .$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> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" height="25"><strong>เรื่อง</strong> ขอสอบแก้ตัว</td>
</tr>
<tr>
<td colspan="2" height="25"><strong>เรียน</strong> รองผู้อำนวยการฝ่ายวิชาการโรงเรียนแม่จันวิทยาคม</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" align="center" height="30"><strong>ข้าพเจ้า</strong> <?php echo $prenamestd ?><?php echo $firstnamestd ?> <?php echo $lastnamestd ?> <strong>เลขประจำตัวนักเรียน</strong> <?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 $lastnameTea</td>
</tr>";
$number++;
}
?>
</table></td>
</tr>
<tr>
<td colspan="2"><div style="margin-left: 50px;">จึงเรียนมาเพื่อโปรดพิจารณา</div></td>
</tr>
<tr>
<td colspan="2"> </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> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">
<strong>ความเห็นของฝ่ายงานวัดผล</strong> [ ] เห็นควรอนุมัติให้ดำเนินการได้ [ ] ...........................................................<br><br>
ลงชื่อ…………………………………………………………….……….ครูวัดผล
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">
<strong>ความเห็นของรองผู้อำนวยการ ฝ่ายวิชาการ</strong><br /><br />
[ ] อนุมัติ,แจ้งครูผู้สอนดำเนินการ [ ] ไม่อนุมัติ </td>
</tr>
<tr>
<td> </td>
<td> </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>
รูปการแสดงผล
- mindphp
- ผู้ดูแลระบบ MindPHP
- โพสต์: 41117
- ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
- ติดต่อ:
Re: สอบถามการออกรายงาน mpdf ใน php สอบถามเรื่องการออกรายงานของ mpdf ใน php
เตรียมตัวแปลให้ พร้อมก่อน เอาเข้า
อาจแทนเป็น
โค้ด: เลือกทั้งหมด
$mpdf->WriteHTML('<br>วันที่ลงทะเบียน ' .$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
ติดตาม 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
- ตอบกลับ
- แสดง
- โพสต์ล่าสุด
-
-
โพสต์ใหม่ วิธีใช้ Google Charts ให้แสดงบน PDF โดยใช้ MPDF
โดย eange08 » 23/12/2020 3:42 pm » ใน PHP Knowledge - 0 ตอบกลับ
- 2586 แสดง
-
โพสต์ล่าสุด โดย eange08
23/12/2020 3:42 pm
-
ผู้ใช้งานขณะนี้
สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 46