954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Using MPDF Library

Hi..

I am using MPDF Library to convert my php page into a pdf format. I've displayed already the needed data from my database but my problem is that not all data in the row are being displayed in the pdf. I am having a hard time to display all data in the row..Can someone help me with this problem? Thanks..

<?php

	session_start();
	include 'configuration.php';
	
	$event= "football";
	$sql = "SELECT * FROM schedule WHERE event= '$event' AND day=1";
	$result = mysql_query($sql);  

		  	while ($rows = mysql_fetch_array($result)) {  			
		  	
			$html = '<html><body><h4><center>Event Schedule</center></h4>';
			$html .= '<table class = "bpmTopnTailC" align="center"><thead>
						<tr class="headerrow">
						<th>Competing Team' . "<br/> ". $rows['team'] . '</th>
						<td><p>Date</p>' . $rows['date'] . '</td>
						<td><p>Time</p>' . $rows['time'] . '</td>
						<td><p>Venue</p>' . $rows['venue'] . '</td>
						</tr></thead></table>';			
						
	
		  	}
	$html .= '</body></html>';
	
	include("mpdf.php");

	$mpdf=new mPDF('c','A4','','',32,25,27,25,16,13); 

	$mpdf->list_indent_first_level = 0;	// 1 or 0 - whether to indent the first level of a list
	
	// LOAD a stylesheet
	$stylesheet = file_get_contents('mpdfstyletables.css');
	$mpdf->WriteHTML($stylesheet,1);	// The parameter 1 tells that this is css/style only and no body/html/text
	
	$mpdf->WriteHTML($html,2);
	
	$mpdf->Output('mpdf.pdf','I');
	exit;
?>
ms.rhea
Newbie Poster
8 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

Hi,
May be the issue is with this line (which is inside while loop)

$html = '<html><body><h4><center>Event Schedule</center></h4>';

Take it above while loop and secondly its better to write this line above while loop

$html .= '<table class = "bpmTopnTailC" align="center"><thead>

and just create the table rows inside while-loop like this

while ($rows = mysql_fetch_array($result)) {
 
$html .= '
<tr class="headerrow">
<th>Competing Team' . "<br/> ". $rows['team'] . '</th>
<th><p>Date</p>' . $rows['date'] . '</th>
<th><p>Time</p>' . $rows['time'] . '</th>
<th><p>Venue</p>' . $rows['venue'] . '</th>
</tr>';
 
 
}

$html .= '</thead></table>';
$html .= '</body></html>';


and so on . . .
Hope this will be helpful to you :)

adkhan
Newbie Poster
24 posts since Oct 2009
Reputation Points: 35
Solved Threads: 8
 

I've tried it and i got a blank page..

ms.rhea
Newbie Poster
8 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

I can't believe that your previous code was working absolutely fine, and i think only last row was just displayed !
And secondly the way which i told you earlier is working fine for me, i used almost the same way to generate an invoice...

adkhan
Newbie Poster
24 posts since Oct 2009
Reputation Points: 35
Solved Threads: 8
 

Yes,only the last row was displayed. I need the all the rows from my table to be displayed. Is there a problem in my MPDF Library?

ms.rhea
Newbie Poster
8 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

No, the problem is not with the MPDF library. Its with your code!
Actually i misunderstood the question before.
Just take this line outside the while loop ...

$html = '<html><body><h4><center>Event Schedule</center></h4>';

But still now your approach is not good. For every single record a new table will be created.
You can use the code which i wrote in previous post, its fine except only i missed ending quote of this line:

$html .= '<table class = "bpmTopnTailC" align="center"><thead>'; /* i missed '; before */

Try these things and let me know!

adkhan
Newbie Poster
24 posts since Oct 2009
Reputation Points: 35
Solved Threads: 8
 

Whew..the code works but it display two tables, instead of one table only.. I need one table displaying all the rows from table of my database..

ms.rhea
Newbie Poster
8 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

You have to create table rows inside while loop as i wrote before in the previous post...
Use this code and try,

session_start();
include 'configuration.php';
 
$event= "football";
$sql = "SELECT * FROM schedule WHERE event= '$event' AND day=1";
$result = mysql_query($sql);
$html = '<html><body><h4><center>Event Schedule</center></h4>';
$html .= '<table class = "bpmTopnTailC" align="center"><tbody>';

    while ($rows = mysql_fetch_array($result)) {
     
    $html .= '
    <tr class="headerrow">
    <td>Competing Team' . "<br/> ". $rows['team'] . '</td>
    <td><p>Date</p>' . $rows['date'] . '</td>
    <td><p>Time</p>' . $rows['time'] . '</td>
    <td><p>Venue</p>' . $rows['venue'] . '</td>
    </tr>';
     
     
    }
     
    $html .= '</tbody></table></body></html>';
/* rest of code here */


Hope this works :)

adkhan
Newbie Poster
24 posts since Oct 2009
Reputation Points: 35
Solved Threads: 8
 

Your code actually display all the rows of my table but then it actually display two table instead of one.. hmmm :(

ms.rhea
Newbie Poster
8 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

But how ? i am unable to figure out this thing from the above given code that two tables will be printed !!!
May be the issue is with your css styling ??
Two tables are displayed on a single page? If the rows exceed from a single page, MPDF starts another table from next page but not on a single page...
Echo $html variable and write exit; before passing to output() function and then check whats the issue ...

adkhan
Newbie Poster
24 posts since Oct 2009
Reputation Points: 35
Solved Threads: 8
 

I got two tables again.. What's wrong with my CCS styling?

ms.rhea
Newbie Poster
8 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 
<?php

require('connect1.php');

mysql_query("SET NAMES 'utf8'", $db);
$result = mysql_query("SELECT * FROM users WHERE id_user=2") or die(mysql_error());;

$html='<html><body><fieldset id="meros_A">
<legend>ΜΕΡΟΣ Α : Στοιχεία αιτητή/τριας</legend>
<table id="stoixeia">';
while($row = mysql_fetch_array($result))
  {
 $html .= '

<tr>
<td align=justify><b>Επώνυμο:</b></td>
<td align=justify>  $row['last_name'] </td>
</tr>
<tr><td align=justify><b>Όνομα:</b></td>
<td align=justify> $row['first_name']; </td>
</tr>
<tr>
<td align=justify><b>Όνομα πατρός:</b></td>
<td align=justify> $row['fathers_name']; </td>
</tr>
<tr>
<td align=justify><b>Υπηκοότητα:</b></td>
<td align=justify> $row["nationality"]; </td>
</tr>
<tr>
<td align=justify><b>Αριθμός δελτίου ταυτότητας/διαβατηρίου:</b></td>
<td align=justify>< $row["identity_card"]; </td>
</tr>
<tr>
<td align=justify><b>Διεύθυνση επικοινωνίας:</b> </td>
<td align=justify> echo $row["address"] ;</td>
</tr>
<tr>
<td align=justify><b>Ηλεκτρονική διεύθυνση(email):</b> </td>
<td align=justify>echo $row["email"] ;</td>
</tr>

<tr>
<td align=justify><b>Τηλέφωνο:</b> </td>
<td align=justify>echo $row["telephone_a"]; </td>
</tr>';
}
$html .= '</table>
</fieldset>';


$html .= '</body></html>';

  
  require_once('mpdf.php');
 $mpdf = new mPDF();
 $mpdf->WriteHTML($html);
  exit;


  
?>

I allways get a blank page :)

emilakia
Newbie Poster
8 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: