Bonjour,

Je souhaite transformer un tableau en PDF. Ceci est réussi grâce à FPDF ou encore DOMPDF mais seulement pour du contenu en HTML.
Cependant ça ne fonctionne plus dès qu'il y a quelques balises php et une requête sql.

Pourriez vous m'aider? Comment je dois procéder?

Code de base
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
 
require_once('connexion.php');
 
if(isset($_POST['date'])) $date=$_POST['date']; else $date="";
if(isset($_POST['datedeux'])) $datedeux=$_POST['datedeux']; else $datedeux="";
 
echo "</br>";
?>
<div align = "center">
<h3><?php echo $date; ?></h3>
</div>
 
<?php
$sql = "SELECT * FROM `registre` WHERE `entree` BETWEEN '".$date." 00:00:00.00' AND '".$datedeux." 23:59:59.999' ORDER BY `entree` ASC";
$resultat = $mysqli->query($sql);
?>
 
<table>
        <tr>
            <td><b> Nom <b/></td>
            <td><b> Prenom <b/></td>
            <td><b> Societe <b/></td>
            <td><b> Service <b/></td>
            <td><b> ID <b/></td>
            <td><b> Motif <b/></td>
            <td><b> Entrée <b/></td>
            <td><b> Sortie <b/></td>
            <td><b> Sortie par DCT <b/></td>
        </tr>
 
<?php      
while($donnees = mysqli_fetch_assoc($resultat))
    {
?>
        <tr>
 
            <td><?php echo $donnees['nom']?> </td>
            <td><?php echo $donnees['prenom']?> </td>
            <td><?php echo $donnees['societe']?> </td>
            <td><?php echo $donnees['service']?> </td>
            <td><?php echo $donnees['id']?> </td>
            <td><?php echo $donnees['motif']?> </td>
            <td><?php echo $donnees['entree']?> </td>
            <td><?php echo $donnees['sortie']?> </td>
            <td align="center"><?php echo $donnees['sortiepardct']?> </td>
 
        </tr>
 
 
<?php      
}
?>
Et voici un test fonctionnel avec dompdf

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
 
$html = "<table border='1' width='100%' style='border-collapse: collapse;'>
        <tr>
            <th>Nom</th>
            <th>Prenom</th>
            <th>Societe</th>
            <th>Service</th>
            <th>ID</th>
            <th>Motif</th>
            <th>Entrée</th>
            <th>Sortie</th>
            <th>Sortie par DCT</th>
        </tr>
 
        <tr>     
            <td>test </td>
            <td>test </td>
            <td>test </td>
            <td>test </td>
            <td>test </td>
            <td>test </td>
            <td>test </td>
            <td>test </td>
            <td>test </td>
        </tr>
 </table>";
 $filename = "newpdffile";
 
// include autoloader
require_once 'dompdf/autoload.inc.php';
// reference the Dompdf namespace
use Dompdf\Dompdf;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream($filename,array("Attachment"=>0));
 
?>
Code non fonctionnel:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
 
require_once('connexion.php');
 
if(isset($_POST['date'])) $date=$_POST['date']; else $date="";
if(isset($_POST['datedeux'])) $datedeux=$_POST['datedeux']; else $datedeux="";
 
echo "</br>";
?>
<div align = "center"> 
<h3><?php echo $date; ?></h3>
</div>
<?php
$sql = "SELECT * FROM `registre` WHERE `entree` BETWEEN '".$date." 00:00:00.00' AND '".$datedeux." 23:59:59.999' ORDER BY `entree` ASC";
$resultat = $mysqli->query($sql);
?>
 
<?php
 
$html = "<table border='1' width='100%' style='border-collapse: collapse;'>
		<tr>
			<td><b> Nom <b/></td>
			<td><b> Prenom <b/></td>
			<td><b> Societe <b/></td>
			<td><b> Service <b/></td>
			<td><b> ID Disney <b/></td>
			<td><b> Motif <b/></td>
			<td><b> Entrée <b/></td>
			<td><b> Sortie <b/></td>
			<td><b> Sortie par DCT <b/></td>
		</tr>
		
<?php		
while($donnees = mysqli_fetch_assoc($resultat)) 
	{  
?>
		<tr>
			<td><?php echo $donnees['nom']?> </td>
			<td><?php echo $donnees['prenom']?> </td>
			<td><?php echo $donnees['societe']?> </td>
			<td><?php echo $donnees['service']?> </td>
			<td><?php echo $donnees['iddisney']?> </td>
			<td><?php echo $donnees['motif']?> </td>
			<td><?php echo $donnees['entree']?> </td>
			<td><?php echo $donnees['sortie']?> </td>
			<td><?php echo $donnees['sortiepardct']?> </td>
		</tr>	
 
 
<?php		
	} 
?>
 
 </table>";
 $filename = "newpdffile";
 
// include autoloader
require_once 'dompdf/autoload.inc.php';
// reference the Dompdf namespace
use Dompdf\Dompdf;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream($filename,array("Attachment"=>0));
 
</body>
</html>