IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques et frameworks PHP Discussion :

[FPDF] transformer un table en pdf


Sujet :

Bibliothèques et frameworks PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Février 2007
    Messages
    219
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 219
    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?

  2. #2
    Membre émérite
    Avatar de jc_cornic
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    623
    Détails du profil
    Informations personnelles :
    Âge : 50
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 623
    Par défaut
    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

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Février 2007
    Messages
    219
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 219
    Par défaut
    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 : 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
    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,...

  4. #4
    Membre émérite
    Avatar de ozzmax
    Inscrit en
    Novembre 2005
    Messages
    977
    Détails du profil
    Informations personnelles :
    Âge : 43

    Informations forums :
    Inscription : Novembre 2005
    Messages : 977
    Par défaut
    Bonjour
    quand tu fais afficher tes variable dans ta table actuellement..ca fonctionne en faisant un truc du genre comme tu fais?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : 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
     
    ...
    <?
    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>
    ';
    ?>
    ...

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Février 2007
    Messages
    219
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 219
    Par défaut
    Merci je vais essayer ça

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Transformation matrice / table
    Par spirou33 dans le forum Access
    Réponses: 6
    Dernier message: 25/10/2007, 16h28
  2. Transformation de tables
    Par Valère dans le forum Langage SQL
    Réponses: 4
    Dernier message: 28/03/2006, 15h32
  3. [FPDF] génération d'attestation en PDF avec PHP
    Par moabomotal dans le forum Bibliothèques et frameworks
    Réponses: 2
    Dernier message: 15/03/2006, 13h50
  4. Réponses: 1
    Dernier message: 16/11/2005, 17h19
  5. [FPDF] Générer de larges documents PDF
    Par LEK dans le forum Bibliothèques et frameworks
    Réponses: 8
    Dernier message: 28/10/2005, 20h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo