Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks > PDF > FPDF
FPDF Forum d'entraide pour la bibliothèque FPDF permettant de générer des documents PDF en PHP. Avant de poster -> tutoriels FPDF
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 20/04/2007, 19h11   #1
Nouveau Membre du Club
 
Inscription : février 2007
Messages : 219
Détails du profil
Informations forums :
Inscription : février 2007
Messages : 219
Points : 32
Points : 32
Par défaut [FPDF] transformer un table en pdf

Bonjour
Dans mon fichier php, je crée un tableau avec "table" et des données que je récupère dans ma base de données et qui changent tous les jours. Je voudrais donc transformer ce table en pdf. J'ai essayé plein de truc mais vu que j'ai des "while", "for",... ça ne marche. Comment faire?
coco38 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/04/2007, 20h15   #2
Membre expérimenté
 
Avatar de jc_cornic
 
Inscription : octobre 2006
Messages : 624
Détails du profil
Informations personnelles :
Âge : 36

Informations forums :
Inscription : octobre 2006
Messages : 624
Points : 588
Points : 588
Envoyer un message via MSN à jc_cornic
Bonsoir, un peu de code serait le bienvenu...

Comment créez vous votre table html, comment essayez vous de la transposer en tableau compatible phpToPDF...
Qu'est-ce qui ne marche pas ???

++
JC
__________________
VELOMASTER, idée cadeau ? un jeu de plateau

Hummmmm, des donuts !!!!

Merci de penser à , et et aussi
jc_cornic est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/04/2007, 11h03   #3
Nouveau Membre du Club
 
Inscription : février 2007
Messages : 219
Détails du profil
Informations forums :
Inscription : février 2007
Messages : 219
Points : 32
Points : 32
Bah vous montre mon code pour construire le tableau, c'est un peu long et en plus, il y a des colonnes fusionnées et fpdf naime pas ça...:
Code :
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<table width=* border=1 cellspacing=0 cellpadding=5>
<tr align=center valign=center>
  <td rowspan=2><strong><? echo("$jj/$mm/$aa");?></td>
<?
$sql = "SELECT * FROM regions ORDER BY regions_nom;";
$result = mysql_query($sql);
$m = 0;
while ($rs = mysql_fetch_array($result)) {
  $m++;
  $regions_nom = $rs['regions_nom'];
?>
  <td colspan=2><strong><?=$regions_nom;?></strong></td>
<? } ?>
  <td rowspan=2><strong>Total<br>vrac</strong></td>
  <td rowspan=2><strong>Total<br>cond.</strong></td>
</tr>
<tr align=center valign=center>
<? for ($i=1;$i<=$m;$i++) { ?>
  <td><strong>Brut.</strong></td>
  <td><strong>Cond.</strong></td>
<? } ?>
</tr>
 
<?
$sql = "SELECT COUNT(*) AS nbre FROM regions;";
$result = mysql_query($sql);
$rs = mysql_fetch_array($result);
$cpt = $rs['nbre'];
$tfruits = array('nb','NB','nj','NJ','pb','PB','pj','PJ');
$totalb = array();
$totalc = array();
$tb = 0;
$tc = 0;
for ($n=1;$n<=$cpt;$n++) {
  $totalb[$n] = 0;
  $totalc[$n] = 0;
}
?>
 
<? for ($k=1;$k<=4;$k++) { ?>
<tr align=center>
  <td><strong><?=$tfruits[($k*2)-1];?></strong></td>
<?
$sql = "SELECT * FROM regions ORDER BY regions_nom;";
$result = mysql_query($sql);
$i=0;
$tvrac = 0;
$tcond = 0;
$nvrac = 0;
$ncond = 0;
while ($rs = mysql_fetch_array($result)) {
  $i++; // cpt cols
  $regions_id = $rs['regions_id'];
  // stock vrac
  $typ = "volq_".$tfruits[($k-1)*2]."_sb";
  $sqlt = "SELECT SUM($typ) AS nbre FROM volq, operateurs WHERE volq.operateurs_id = operateurs.operateurs_id AND volq_jj = $jj AND volq_mm = $mm AND volq_aa = $aa AND operateurs.regions_id = $regions_id;";
  $resultt = mysql_query($sqlt);
  $rt = mysql_fetch_array($resultt);
  if (!empty($rt['nbre']))
    $nvrac = $rt['nbre'];
  else $nvrac = 0;
  $tvrac = $tvrac+$nvrac;
  // stock cond
  $typ = "volq_".$tfruits[($k-1)*2]."_sc";
  $sqlt = "SELECT SUM($typ) AS nbre FROM volq, operateurs WHERE volq.operateurs_id = operateurs.operateurs_id AND volq_jj = $jj AND volq_mm = $mm AND volq_aa = $aa AND operateurs.regions_id = $regions_id;";
  $resultt = mysql_query($sqlt);
  $rt = mysql_fetch_array($resultt);
  if (!empty($rt['nbre']))
    $ncond = $rt['nbre'];
  else $ncond = 0;
  $tcond = $tcond+$ncond;
  $totalb[$i] = $totalb[$i] + $nvrac;
  $totalc[$i] = $totalc[$i] + $ncond;
  $tb = $tb+$nvrac;
  $tc = $tc+$ncond;
?>
  <td><?=$nvrac;?></td>
  <td><?=$ncond;?></td>
<? } ?>
  <td><strong><?=$tvrac;?></strong></td>
  <td><strong><?=$tcond;?></strong></td>
</tr>
<? } ?>
 
<tr align=center>
  <td><strong>TOTAL</strong></td>
  <? for ($n=1;$n<=$cpt;$n++) { ?>
    <td><strong><?=$totalb[$n];?></strong></td>
    <td><strong><?=$totalc[$n];?></strong></td>
  <? } ?>
  <td><strong><?=$tb;?></strong></td>
  <td><strong><?=$tc;?></strong></td>
</tr>
 
</table>
Donc après j'utilise fpdf avec un code qui transforme le 'table' en pdf mais il me traduit pas mes while,...
coco38 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/04/2007, 18h53   #4
Membre émérite
 
Avatar de ozzmax
 
Inscription : novembre 2005
Messages : 986
Détails du profil
Informations personnelles :
Âge : 29

Informations forums :
Inscription : novembre 2005
Messages : 986
Points : 863
Points : 863
Envoyer un message via MSN à ozzmax
Bonjour
quand tu fais afficher tes variable dans ta table actuellement..ca fonctionne en faisant un truc du genre comme tu fais?
Code :
1
2
3
 
<td><strong><?=$tvrac;?></strong></td>
<td><strong><?=$tcond;?></strong></td>
Je veux dire ca affiche dans ta page?
c'est p-e de là que viens le probleme
si tu fais quelque chose comme ca à la place
Code :
1
2
3
 
<td><strong><? echo $tvrac; ?></strong></td>
<td><strong><? echo $tcond; ?></strong></td>
personnelement je ferais tout en php meme tes sorties html pour éviter d'ouvrir et fermer les balise de code a répétition..
exemple
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
...
<?
echo'
<tr align=center>
  <td><strong>TOTAL</strong></td>
';
  for ($n=1;$n<=$cpt;$n++) {
   echo'
    <td><strong>'.$totalb[$n].'</strong></td>
    <td><strong>'.$totalc[$n].'</strong></td>
   ';
  }
echo'
  <td><strong>'.$tb.'</strong></td>
  <td><strong>'.$tc.'</strong></td>
</tr>
';
?>
...
__________________
La perfection n'est pas un but, l'amélioration constante devrait l'être!
La position des Développeurs de developpez avec les explications
ozzmax est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/04/2007, 18h55   #5
Nouveau Membre du Club
 
Inscription : février 2007
Messages : 219
Détails du profil
Informations forums :
Inscription : février 2007
Messages : 219
Points : 32
Points : 32
Merci je vais essayer ça
coco38 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 10h14.


 
 
 
 
Partenaires

Hébergement Web