Bonjour à tous,
Je voudrai créer un fichier PDF à partir d'une recherche dans une base de donnée.
Voici mon code pour extraire les données de la 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
$columns = 2;
echo "<table class=\"values_table\" summary=\"données introduits\">";
$pdf = $pdf."<table class=\"values_table\" summary=\"données introduits\">";
echo"<thead>"; 
$pdf = $pdf."<thead>";
echo"<th scope=\"colgroup\">Site</th>";
$pdf = $pdf."<th scope=\"colgroup\">Site</th>";
echo"<th scope=\"colgroup\">temp(°C)</th>";
$pdf = $pdf."<th scope=\"colgroup\">temp(°C)</th>";
echo"</thead>";
echo"<tbody>";
$pdf = $pdf."</thead><tbody>" ;
 
if ($result = $mysqli->query($v_query))
{
   while($row = $result->fetch_row())
   {
      echo "<tr>";
      $pdf = $pdf."<tr>";
      $num_col = 0;
      while ($num_col < $columns)
      {
         echo "<td class=\"__field__\">". $row[$num_col] . "</td>";
         $num_col = $num_col + 1;
         $pdf = $pdf."<td class=\"__field__\">". $row[$num_col] . "</td>";<br>
      }
      echo "</tr>";
      $pdf = $pdf."</tr>";<br>
}
echo"</tbody>";
echo "</table>";
 
$pdf = $pdf."</tbody></table>" ;
 
}
$_SESSION['pdf'] = $pdf ;
Et voici mon code pour créer le fichier PDF :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
<?php
session_start() ;
require_once("dompdf/dompdf_config.inc.php");
 
$html = $_SESSION['pdf'];
 
$dompdf = new DOMPDF();
$dompdf->load_html(utf8_encode($html));
$dompdf->render();
$dompdf->stream("mon_fichier.pdf");
 
?>

Il y a un problème au moment de la création du fichier.
J'ai fais un echo sur la variable $html, il y a bien un tableau avec mes données, alors je ne comprend pas pk le fichier ne se crée pas.

Cordialement
Adrien