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;
?>

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 :)

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

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...

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?

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!

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..

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 :)

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

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 ...

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

<?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 :)

what programming you are doing and what case study you have done befdore starting to work with MPDF

use this $mpdf->Output('$file_name',F);before exit

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.