Function /class donnée requete sql

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Function /class donnée requete sql

Re: Function /class donnée requete sql

par moogli » 27 avr. 2013, 13:28

tu prend tous les code de la classe PDF_MC_Table un bon gros coupé dessus.
tu créer un nouveau fichier avec ton éditeur de texte ou ide préféré et tu colle le tout de dans. (n'oublie pas le <?php en 1ère ligne ;) )

ensuite à la place de ce code dans la première page tu met un include du fichier tous neuf ce sera plus claire.

j'ai corrigé ton code pour être plus fonctionnel et à jour (utilisation de mysqli plutôt que mysql). Tu passe la ressource de connexion myslqi dans la fonction et l'utilise etc etc
<?php
function generationpdf($id_bc, $dbconnexion) {
// Afficher les erreurs à l'écran
    ini_set('display_errors', 1);
// Enregistrer les erreurs dans un fichier de log
    ini_set('log_errors', 1);
// Nom du fichier qui enregistre les logs (attention aux droits à l'écriture)
    ini_set('error_log', dirname(__file__) . '/log_error_php.txt');
// Afficher les erreurs et les avertissements

    if (file_exists("bc.pdf")) {
        unlink("bc.pdf");
    }
    $requete = 'SELECT bc.id_bc, bc_dematerialise, bc_document, type, size, name, u.nom AS nom, u.prenom AS prenom,
        date_format( bc.date, \'%d/%m/%Y\' ) AS date, uv.nom AS uvnom, uv.prenom AS uvprenom,
        date_format(bc.date_users_valid, \'%d/%m/%Y\') as datevalider,
        FORMAT(SUM(bca.qte),2) as qte_total, FORMAT(SUM(bca.prix_unitaire*bca.qte),2) as prix_total,
        s.nom AS societe, s.capital as capital, s.ntva_intra as ntva_intra, s.siren as siren, s.code_ape as ape,
        s.adresse AS asociete, s.ville AS sville, s.cp AS scp, c.siret AS siret, c.nom AS cnom, c.adresse AS cadresse,
        c.ville AS cville, c.cp AS ccp, c.tel AS ctel, c.fax AS cfax
    FROM boncommande bc
     JOIN boncommande_article bca ON bca.id_bc=bc.id_bc
     JOIN users u ON bc.id_users = u.id_users
     JOIN societe s ON bc.id_societe = s.id_societe
     JOIN concessions c ON bc.id_concessions = c.id_concessions
     JOIN fournisseurs f ON bc.id_fournisseur=f.id_fournisseur
     JOIN services serv ON bc.id_services=serv.id_services
     JOIN users uv ON bc.id_users_valid = uv.id_users
    WHERE bc.id_bc = ' . mysqli_real_escape_string($dbconnexion, $id_bc);
    $ret = mysqli_query($dbconnexion, $requete);
    if ($ret === false) {
        echo 'Erreur SQL ligne :', __LINE__, ' <br />',
        mysqli_error($dbconnexion)
        , 'Avec la requête : ', $requete, '<br />';
    } else {
        $list0 = mysqli_fetch_assoc($ret);

        if ($list0["bc_dematerialise"] == 1) {
            //chmod("bc.pdf", 0755);
            $nom_file = "bc.pdf";
            // création du fichier
            $f = fopen($nom_file, "x+");
            // écriture
            fputs($f, $list0["bc_document"]); // c'est un pdf stockée en base ?
            // fermeture$dbconnexion    
            fclose($f);

            $pdf = new FPDI();
            // add a page
            $pdf->AddPage();
            // set the sourcefile
            $pdf->setSourceFile('bc.pdf'); // pas moyen de fournir directement le contenu ?
            // import page 1
            $tplIdx = $pdf->importPage(1);
            // use the imported page and place it at point 10,10 with a width of 100 mm
            $pdf->useTemplate($tplIdx, 10, 10, 100);

            // now write some text above the imported page
            $pdf->SetFont('Arial');
            $pdf->SetXY(35, 200);
            $pdf->MultiCell(120, 5, " LE BON COMMANDE  N°" . $list0["id_bc"] . " \n  à été créé par " . $list0["nom"] . " " . $list0["prenom"] . "(" . $list0["date"] . ") \n Validé par:" . $list0["uvnom"] . "" . $list0["uvprenom"] . "(le " . $list0["datevalider"] . ")");
            $pdf->Output("boncommande-" . $list0["id_bc"] . ".pdf", "F");
            unlink("bc.pdf");
        } else {
            include 'pdf_mc_table.php';

            $pdf = new PDF_MC_Table();
            $pdf->AddPage();
            $pdf->SetWidths(array(24, 30, 48, 25, 15, 18, 18));
            $pdf->SetFont('Arial', '', 10);
            $pdf->SetAutoPageBreak(true, 55);

            $pdf->Row(array("Marque", "Ref_int", "Description", "N_Or/IMMAT", "Qte", "Prix U HT", "Total HT"));
            $sql2 = 'select m.nom marque, ref_int as Reference, descriptif, ref_or as N_OR, FORMAT(qte,2) as Qte,
                    FORMAT(prix_unitaire,2) as Prix, FORMAT((qte*prix_unitaire),2)  as totalht
                    FROM boncommande_article bca
                    INNER JOIN marque m ON m.id_marque=bca.id_marque
                    WHERE bca.id_bc=' . mysqli_real_escape_string($dbconnexion, valid_data($id_bc));

            $query2 = mysqli_query($dbconnexion, $sql2);
            if ($query2 === false) {
                echo 'Erreur SQL ligne :', __LINE__, ' <br />',
                mysqli_error($dbconnexion)
                , 'Avec la requête : ', $sql2, '<br />';
            } else {
                while ($list2 = mysqli_fetch_assoc($query2)) {
                    $pdf->Row(array($list2["marque"], $list2["Reference"], $list2["descriptif"], $list2["N_OR"],
                        $list2["Qte"], $list2["Prix"], $list2["totalht"]));
                }
            }
            $pdf->Output("boncommande-" . $list0["id_bc"] . ".pdf", "F");
        }
    }
}
et le fichier pdf_mc_table.php qui contient la classe
<?php 
class PDF_MC_Table extends FPDF {
    protected $widths;
    protected $aligns;


    protected $ProcessingTable = false;
    protected $aCols = array();
    protected $TableX = 10;
    protected $HeaderColor;
    protected $RowColors;
    protected $ColorIndex;


    public function TableHeader() {
        $this->SetFont('Arial', 'B', 12);
        $this->SetX($this->TableX);
        $fill = !empty($this->HeaderColor);
        if ($fill)
            $this->SetFillColor($this->HeaderColor[0], $this->HeaderColor[1], $this->HeaderColor[2]);
        foreach ($this->aCols as $col)
            $this->Cell($col['w'], 6, $col['c'], 1, 0, 'C', $fill);
        $this->Ln();
    }

    public function AddCol($field = -1, $width = -1, $caption = '', $align = 'L') {
        //Ajoute une colonne au tableau
        if ($field == -1)
            $field = count($this->aCols);
        $this->aCols[] = array('f' => $field, 'c' => $caption, 'w' => $width, 'a' => $align);
    }

    public function RoundedRect($x, $y, $w, $h, $r, $style = '') {
        $k = $this->k;
        $hp = $this->h;
        if ($style == 'F')
            $op = 'f';
        elseif ($style == 'FD' || $style == 'DF')
            $op = 'B'; else
            $op = 'S';
        $MyArc = 4 / 3 * (sqrt(2) - 1);
        $this->_out(sprintf('%.2F %.2F m', ($x + $r) * $k, ($hp - $y) * $k));
        $xc = $x + $w - $r;
        $yc = $y + $r;
        $this->_out(sprintf('%.2F %.2F l', $xc * $k, ($hp - $y) * $k));

        $this->_Arc($xc + $r * $MyArc, $yc - $r, $xc + $r, $yc - $r * $MyArc, $xc + $r, $yc);
        $xc = $x + $w - $r;
        $yc = $y + $h - $r;
        $this->_out(sprintf('%.2F %.2F l', ($x + $w) * $k, ($hp - $yc) * $k));
        $this->_Arc($xc + $r, $yc + $r * $MyArc, $xc + $r * $MyArc, $yc + $r, $xc, $yc + $r);
        $xc = $x + $r;
        $yc = $y + $h - $r;
        $this->_out(sprintf('%.2F %.2F l', $xc * $k, ($hp - ($y + $h)) * $k));
        $this->_Arc($xc - $r * $MyArc, $yc + $r, $xc - $r, $yc + $r * $MyArc, $xc - $r, $yc);
        $xc = $x + $r;
        $yc = $y + $r;
        $this->_out(sprintf('%.2F %.2F l', ($x) * $k, ($hp - $yc) * $k));
        $this->_Arc($xc - $r, $yc - $r * $MyArc, $xc - $r * $MyArc, $yc - $r, $xc, $yc - $r);
        $this->_out($op);
    }

    public function _Arc($x1, $y1, $x2, $y2, $x3, $y3) {
        $h = $this->h;
        $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $x1 * $this->k, ($h - $y1) * $this->k,
            $x2 * $this->k, ($h - $y2) * $this->k, $x3 * $this->k, ($h - $y3) * $this->k));
    }

    public function Header($list0) {
        $this->SetFont('Arial', '', 8);
        $this->Image('img/marque.png', 10, 6, 170, 14);
        $this->SetFillColor(200);
        $this->SetFont('');
        $this->RoundedRect(10, 25, 90, 15, 3.5, 'FD');
        $this->SetXY(10, 25);
        $this->SetFillColor(173, 173, 173);
        $this->RoundedRect(10, 40, 90, 25, 3.5, 'FD');
        $this->SetXY(10, 25);
        $this->MultiCell(90, 5, $list0["societe"] . "\n Siren:" . $list0["siren"] . "- Capital:" . $list0["capital"] . " € \n N°TVA Intra:" . $list0["ntva_intra"] . " - APE " . $list0["ape"] . " \n" . $list0["cnom"] . "\n" . $list0["cadresse"] . "\n  " . $list0["ccp"] . " " . $list0["cville"] . "\n Tel: (+33) " . $list0["ctel"] . "\n Tel: (+33) " . $list0["cfax"] . " ", 0);
        $this->RoundedRect(10, 68, 45, 5, 3.5, 'FD');
        $this->SetXY(10, 68);
        $this->MultiCell(90, 5, "Service: " . $list0["nomservices"] . " ", 0);

        $this->SetFillColor(200);
        $this->RoundedRect(125, 25, 70, 10, 3.5, 'FD');
        $this->SetXY(125, 27);
        $this->MultiCell(70, 5, " BON DE COMMANDE N°#" . $list0["id_bc"], 0);
        $this->Ln();
        $this->SetFillColor(225);
        $this->RoundedRect(125, 50, 70, 20, 3.5, 'FD');

        $this->SetXY(125, 55);
        $this->MultiCell(70, 5, "" . $list0["fournisseur"] . "\n " . $list0["fadresse"] . "\n " . $list0["fcp"] . " " . $list0["fville"] . " \n", 0);
        $this->Ln();
        $this->SetFillColor(225);
        $this->RoundedRect(10, 75, 180, 10, 3.5, 'FD');
        $this->MultiCell(180, 10, "Remarque:" . $list0["remarque"] . "", 0);
        $this->Ln();
        $this->SetFillColor(250, 255, 255);
        $this->SetFont('Arial', 'B', 11);
        $this->RoundedRect(10, 95, 180, 10, 3.5, 'FD');
        $this->MultiCell(180, 10, "Joindre ce document à la facture ou bien faire apparaitre le numéro BC #" . $list0["id_bc"], 0, "C");
        //Imprime l'en-tête du tableau si nécessaire
        $this->Ln(10);
        $this->TableHeader();
    }


    public function Footer($list0) {

        $this->SetFillColor(192);
        $this->RoundedRect(10, 255, 70, 5, 3.5, 'FD');
        $this->SetXY(10, 255);
        $this->MultiCell(120, 5, "de:" . $list0["nom"] . " " . $list0["prenom"] . "(" . $list0["date"] . ")", 0);
        $this->RoundedRect(10, 262, 95, 5, 3.5, 'FD');
        $this->SetXY(10, 262);
        $this->MultiCell(120, 5, "Validé par:" . $list0["uvnom"] . "" . $list0["uvprenom"] . "(le " . $list0["datevalider"] . ")", 0);
        $this->RoundedRect(140, 255, 30, 5, 3.5, 'FD');
        $this->SetXY(140, 255);
        $this->MultiCell(80, 5, "Qte :" . $list0["qte_total"] . "", 0);
        $this->RoundedRect(170, 255, 30, 5, 3.5, 'FD');
        $this->SetXY(170, 255);
        $this->MultiCell(80, 5, "Prix :" . $list0["prix_total"] . "", 0);
        // Positionnement à 1,5 cm du bas
        $this->SetY(-15);
        // Police Arial italique 8
        $this->SetFont('Arial', 'I', 8);
        // Numéro de page centré
        $this->Cell(0, 10, 'Page ' . $this->PageNo(), 0, 0, 'C');
    }

    public function Row($data) {
        //Calcule la hauteur de la ligne
        $nb = 0;
        for ($i = 0; $i < count($data); $i++)
            $nb = max($nb, $this->NbLines($this->widths[$i], $data[$i]));
        $h = 5 * $nb;
        //Effectue un saut de page si nécessaire
        $this->CheckPageBreak($h);

        //Dessine les cellules
        for ($i = 0; $i < count($data); $i++) {
            $w = $this->widths[$i];
            $a = isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
            //Sauve la position courante
            $x = $this->GetX();
            $y = $this->GetY();
            //Dessine le cadre
            $this->Rect($x, $y, $w, $h);
            //Imprime le texte
            $this->MultiCell($w, 5, $data[$i], 0, $a);
            //Repositionne à droite
            $this->SetXY($x + $w, $y);
        }
        //Va à la ligne
        $this->Ln($h);
    }

    public function CheckPageBreak($h) {
        //Si la hauteur h provoque un débordement, saut de page manuel
        if ($this->GetY() + $h > $this->PageBreakTrigger)
            $this->AddPage($this->CurOrientation);
    }

    public function NbLines($w, $txt) {
        //Calcule le nombre de lignes qu'occupe un MultiCell de largeur w
        $cw =& $this->CurrentFont['cw'];
        if ($w == 0)
            $w = $this->w - $this->rMargin - $this->x;
        $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;
        $s = str_replace("\r", '', $txt);
        $nb = strlen($s);
        if ($nb > 0 and $s[$nb - 1] == "\n")
            $nb--;
        $sep = -1;
        $i = 0;
        $j = 0;
        $l = 0;
        $nl = 1;
        while ($i < $nb) {
            $c = $s[$i];
            if ($c == "\n") {
                $i++;
                $sep = -1;
                $j = $i;
                $l = 0;
                $nl++;
                continue;
            }
            if ($c == ' ')
                $sep = $i;
            $l += $cw[$c];
            if ($l > $wmax) {
                if ($sep == -1) {
                    if ($i == $j)
                        $i++;
                } else
                    $i = $sep + 1;
                $sep = -1;
                $j = $i;
                $l = 0;
                $nl++;
            } else
                $i++;
        }
        return $nl;
    }
    // setter / getter

    public function setACols($aCols) {
        $this->aCols = $aCols;
    }

    public function getACols() {
        return $this->aCols;
    }

    public function setAligns($aligns) {
        $this->aligns = $aligns;
    }

    public function getAligns() {
        return $this->aligns;
    }

    public function setColorIndex($ColorIndex) {
        $this->ColorIndex = $ColorIndex;
    }

    public function getColorIndex() {
        return $this->ColorIndex;
    }

    public function setHeaderColor($HeaderColor) {
        $this->HeaderColor = $HeaderColor;
    }

    public function getHeaderColor() {
        return $this->HeaderColor;
    }

    public function setProcessingTable($ProcessingTable) {
        $this->ProcessingTable = $ProcessingTable;
    }

    public function getProcessingTable() {
        return $this->ProcessingTable;
    }

    public function setRowColors($RowColors) {
        $this->RowColors = $RowColors;
    }

    public function getRowColors() {
        return $this->RowColors;
    }

    public function setTableX($TableX) {
        $this->TableX = $TableX;
    }

    public function getTableX() {
        return $this->TableX;
    }

    public function setWidths($widths) {
        $this->widths = $widths;
    }

    public function getWidths() {
        return $this->widths;
    }

}
j'ai juste mis en forme + utilisation de la syntaxe php5, passage des propriétés en protected + setter / getter sur ces propriété.

avec ça tu aura des messages d'erreur si besoin.
s'il y a une quelconque utilisation de header après l'utilisation de la fonction (par exemple pour envoyer au navigateur le fichier ou une redirection) met la en commentaire afin d'être certain de voir les messages d'erreur.
même chose pour la méthode Footer.

pour info tu utilise dans la méthode Header une variable qui n'existe pas ($list0). il te faut la passer en paramètre, il s'agit du tableau de la requête ok, mais il n'existe pas dans la classe (voir porté des variables).

A tu place j'utiliserais plutôt un objet perso pour être certain d'avoir les valeur qui m'intéresse (cela évitera une erreur si tu oublie de récupérer le champs siren dans la requête (par exemple) ;)

dernière chose, juste pour info, par convention les noms de méthode commence par des minuscules et les nom de classe par des majuscules. ça n’empêche pas le code de fonctionner mais permet une meilleur lisibilité du code ;)

@+

Re: Function /class donnée requete sql

par guigui69 » 26 avr. 2013, 17:44

Bonsoir,

pourrais tu m'expliquer cela "par exemple en déportant la classe dans un autre fichier. "

Merci d'avance

guigui69

Re: Function /class donnée requete sql

par moogli » 18 janv. 2013, 20:32

salut,


Commence par rendre ton code plus claire, par exemple en déportant la classe dans un autre fichier.

ensuite indique l'emplacement du problème on ne va pas tester tous le code.

as tu un message d'erreur ?


@+

Function /class donnée requete sql

par guigui69 » 17 janv. 2013, 16:20

Bonjour à tous,
function generationpdf($id_bc)
{


// Afficher les erreurs à l'écran
ini_set('display_errors', 1);
// Enregistrer les erreurs dans un fichier de log
ini_set('log_errors', 1);
// Nom du fichier qui enregistre les logs (attention aux droits à l'écriture)
ini_set('error_log', dirname(__file__) . '/log_error_php.txt');
// Afficher les erreurs et les avertissements

if (file_exists("bc.pdf")) 
{
unlink("bc.pdf"); 
} else 
{

} 



$sql=mysql_query("SELECT bc.id_bc, bc_dematerialise, bc_document, type, size, name, u.nom AS nom, u.prenom AS prenom, date_format( bc.date, '%d/%m/%Y' ) AS date, uv.nom AS uvnom, uv.prenom AS uvprenom, date_format(bc.date_users_valid, '%d/%m/%Y') as datevalider,
FORMAT(SUM(bca.qte),2) as qte_total, FORMAT(SUM(bca.prix_unitaire*bca.qte),2) as prix_total,
s.nom AS societe, s.capital as capital, s.ntva_intra as ntva_intra, s.siren as siren, s.code_ape as ape, s.adresse AS asociete, s.ville AS sville, s.cp AS scp, c.siret AS siret, c.nom AS cnom, c.adresse AS cadresse, c.ville AS cville, c.cp AS ccp, c.tel AS ctel, c.fax AS cfax
FROM boncommande bc 
INNER JOIN boncommande_article bca ON bca.id_bc=bc.id_bc
INNER JOIN users u ON bc.id_users = u.id_users
INNER JOIN societe s ON bc.id_societe = s.id_societe
INNER JOIN concessions c ON bc.id_concessions = c.id_concessions
INNER JOIN fournisseurs f ON bc.id_fournisseur=f.id_fournisseur
INNER JOIN services serv ON bc.id_services=serv.id_services
INNER JOIN users uv ON bc.id_users_valid = uv.id_users
WHERE bc.id_bc = '".$id_bc."'");
echo $id_bc;
$list0= mysql_fetch_array( $sql ) ;

if($list0["bc_dematerialise"] ==1)
{
//chmod("bc.pdf", 0755);
$nom_file = "bc.pdf";
// création du fichier
$f = fopen($nom_file, "x+");
// écriture
fputs($f, $list0["bc_document"]);
// fermeture
fclose($f);



$pdf = new FPDI(); 
// add a page 
	$pdf->AddPage(); 
	// set the sourcefile 
	$pdf->setSourceFile('bc.pdf'); 
	// import page 1 
	$tplIdx = $pdf->importPage(1); 
	// use the imported page and place it at point 10,10 with a width of 100 mm 
	$pdf->useTemplate($tplIdx, 10, 10, 100); 
	 
	// now write some text above the imported page 
	$pdf->SetFont('Arial'); 
	$pdf->SetXY(35, 200); 
	$pdf->MultiCell(120,5, " LE BON COMMANDE  N°".$list0["id_bc"]. " \n  à été créé par ".$list0["nom"]. " ". $list0["prenom"]."(". $list0["date"].") \n Validé par:".$list0["uvnom"]. "". $list0["uvprenom"] ."(le ". $list0["datevalider"].")");

	$pdf->Output("boncommande-".$list0["id_bc"]. ".pdf","F"); 
unlink("bc.pdf"); 
}
else
{

class PDF_MC_Table extends FPDF
{
var $widths;
var $aligns;


var $ProcessingTable=false;
var $aCols=array();
var $TableX=10;
var $HeaderColor;
var $RowColors;
var $ColorIndex;


function TableHeader()
{
    $this->SetFont('Arial','B',12);
    $this->SetX($this->TableX);
    $fill=!empty($this->HeaderColor);
    if($fill)
        $this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]);
    foreach($this->aCols as $col)
        $this->Cell($col['w'],6,$col['c'],1,0,'C',$fill);
    $this->Ln();
}

function AddCol($field=-1,$width=-1,$caption='',$align='L')
{
    //Ajoute une colonne au tableau
    if($field==-1)
        $field=count($this->aCols);
    $this->aCols[]=array('f'=>$field,'c'=>$caption,'w'=>$width,'a'=>$align);
}

 function RoundedRect($x, $y, $w, $h, $r, $style = '')
    {
        $k = $this->k;
        $hp = $this->h;
        if($style=='F')
            $op='f';
        elseif($style=='FD' || $style=='DF')
            $op='B';
        else
            $op='S';
        $MyArc = 4/3 * (sqrt(2) - 1);
        $this->_out(sprintf('%.2F %.2F m',($x+$r)*$k,($hp-$y)*$k ));
        $xc = $x+$w-$r ;
        $yc = $y+$r;
        $this->_out(sprintf('%.2F %.2F l', $xc*$k,($hp-$y)*$k ));

        $this->_Arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc);
        $xc = $x+$w-$r ;
        $yc = $y+$h-$r;
        $this->_out(sprintf('%.2F %.2F l',($x+$w)*$k,($hp-$yc)*$k));
        $this->_Arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r);
        $xc = $x+$r ;
        $yc = $y+$h-$r;
        $this->_out(sprintf('%.2F %.2F l',$xc*$k,($hp-($y+$h))*$k));
        $this->_Arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc);
        $xc = $x+$r ;
        $yc = $y+$r;
        $this->_out(sprintf('%.2F %.2F l',($x)*$k,($hp-$yc)*$k ));
        $this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r);
        $this->_out($op);
    }

    function _Arc($x1, $y1, $x2, $y2, $x3, $y3)
    {
        $h = $this->h;
        $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $x1*$this->k, ($h-$y1)*$this->k,
            $x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k));
    }

function Header()
{

	// $sql= "
// SELECT bc.id_bc, u.nom AS nom, u.prenom AS prenom, date_format( bc.date, '%d/%m/%Y' ) AS date, s.nom AS societe, s.capital as capital, s.ntva_intra as ntva_intra, s.siren as siren, s.code_ape as ape, s.adresse AS asociete, s.ville AS sville, s.cp AS scp, c.siret AS siret, c.nom AS cnom, c.adresse AS cadresse, c.ville AS cville, c.cp AS ccp, c.tel AS ctel, c.fax AS cfax, uv.nom AS uvnom, uv.prenom AS uvprenom, date_format(bc.date_users_valid, '%d/%m/%Y') as datevalider, bc.remarque,FORMAT(SUM(bca.qte),2) as qte_total, FORMAT(SUM(bca.prix_unitaire),2) as prix_total, f.nom as fournisseur , f.Adresse as fadresse, f.cp as fcp, f.Ville as fville, serv.nom as nomservices
// FROM boncommande bc
// INNER JOIN boncommande_article bca ON bca.id_bc=bc.id_bc
// INNER JOIN users u ON bc.id_users = u.id_users
// INNER JOIN societe s ON bc.id_societe = s.id_societe
// INNER JOIN concessions c ON bc.id_concessions = c.id_concessions
// INNER JOIN fournisseurs f ON bc.id_fournisseur=f.id_fournisseur
// INNER JOIN services serv ON bc.id_services=serv.id_services
// INNER JOIN users uv ON bc.id_users_valid = uv.id_users
// WHERE bc.id_bc = '".$id_bc."'";
// $query= mysql_query($sql) or die('erreur1');
// $list2 = mysql_fetch_array( $query ); 
	//Titre
	$this->SetFont('Arial','',8);
	$this->Image('img/marque.png',10,6,170,14);

	////////////////////////////
	

	$this->SetFillColor(200);
	$this->SetFont('');
$this->RoundedRect(10, 25, 90, 15, 3.5, 'FD');
	$this->SetXY( 10, 25);
	$this->SetFillColor(173,173,173);
$this->RoundedRect(10, 40, 90, 25, 3.5, 'FD');
	$this->SetXY( 10, 25);
$this->MultiCell(90,5,$list0["societe"]. "\n Siren:".$list0["siren"]."- Capital:".$list0["capital"]." € \n N°TVA Intra:".$list0["ntva_intra"]." - APE ".$list0["ape"]." \n".$list0["cnom"]."\n".$list0["cadresse"]."\n  ".$list0["ccp"]." ". $list0["cville"] ."\n Tel: (+33) ".$list0["ctel"]."\n Tel: (+33) ".$list0["cfax"]." ",0);	
$this->RoundedRect(10, 68, 45, 5, 3.5, 'FD');
	$this->SetXY( 10, 68);
	$this->MultiCell(90,5,"Service: ". $list0["nomservices"]." ",0);	

$this->SetFillColor(200);
$this->RoundedRect(125, 25, 70, 10, 3.5, 'FD');
	$this->SetXY( 125, 27);
$this->MultiCell(70,5," BON DE COMMANDE N°#".$list0["id_bc"],0);	
				$this->Ln();	
$this->SetFillColor(225);
$this->RoundedRect(125, 50, 70, 20, 3.5, 'FD');
				
				$this->SetXY( 125, 55);
			$this->MultiCell(70,5,"".$list0["fournisseur"]."\n ".$list0["fadresse"]."\n ".$list0["fcp"]." ".$list0["fville"]." \n",0);
$this->Ln();	
	$this->SetFillColor(225);
$this->RoundedRect(10, 75, 180, 10, 3.5, 'FD');
	$this->MultiCell(180,10,"Remarque:".$list0["remarque"]."",0);
	$this->Ln();
		$this->SetFillColor(250,255,255);
		$this->SetFont('Arial','B',11);
$this->RoundedRect(10, 95, 180, 10, 3.5, 'FD');
	$this->MultiCell(180,10,"Joindre ce document à la facture ou bien faire apparaitre le numéro BC #".$list0["id_bc"],0, "C");
	//Imprime l'en-tête du tableau si nécessaire
		$this->Ln(10);
        $this->TableHeader();
}
	// $sql="
// SELECT u.nom AS nom, u.prenom AS prenom, date_format( bc.date, '%d/%m/%Y' ) AS date, uv.nom AS uvnom, uv.prenom AS uvprenom, date_format(bc.date_users_valid, '%d/%m/%Y') as datevalider, FORMAT(SUM(bca.qte),2) as qte_total, FORMAT(SUM(bca.prix_unitaire*bca.qte),2) as prix_total
// FROM boncommande bc
// INNER JOIN boncommande_article bca ON bca.id_bc=bc.id_bc
// INNER JOIN users u ON bc.id_users = u.id_users
// INNER JOIN societe s ON bc.id_societe = s.id_societe
// INNER JOIN concessions c ON bc.id_concessions = c.id_concessions
// INNER JOIN users uv ON bc.id_users_valid = uv.id_users
// WHERE bc.id_bc = '".$id_bc."'";
// $query= mysql_query($sql) or die('erreur2');
// $list2 = mysql_fetch_array( $query ); 

function Footer()
{

	$this->SetFillColor(192);
   $this->RoundedRect(10, 255, 70, 5, 3.5, 'FD');
	$this->SetXY( 10, 255);
	$this->MultiCell(120,5,"de:".$list0["nom"]. " ". $list0["prenom"]."(". $list0["date"].")",0);		
	$this->RoundedRect(10, 262, 95, 5, 3.5, 'FD');
	$this->SetXY( 10, 262);
	$this->MultiCell(120,5,"Validé par:".$list0["uvnom"]. "". $list0["uvprenom"] ."(le ". $list0["datevalider"].")",0);	
	$this->RoundedRect(140, 255, 30, 5, 3.5, 'FD');
	$this->SetXY( 140, 255);
	$this->MultiCell(80,5,"Qte :".$list0["qte_total"]. "",0);		
	$this->RoundedRect(170, 255, 30, 5, 3.5, 'FD');
	$this->SetXY( 170, 255);
	$this->MultiCell(80,5,"Prix :".$list0["prix_total"]. "",0);	
    // Positionnement à 1,5 cm du bas
    $this->SetY(-15);
    // Police Arial italique 8
    $this->SetFont('Arial','I',8);
    // Numéro de page centré
    $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}


function SetWidths($w)
{
    //Tableau des largeurs de colonnes
    $this->widths=$w;
}

function SetAligns($a)
{
    //Tableau des alignements de colonnes
    $this->aligns=$a;
}

function Row($data)
{
    //Calcule la hauteur de la ligne
    $nb=0;
    for($i=0;$i<count($data);$i++)
        $nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
    $h=5*$nb;
    //Effectue un saut de page si nécessaire
    $this->CheckPageBreak($h);

    //Dessine les cellules
    for($i=0;$i<count($data);$i++)
    {
        $w=$this->widths[$i];
        $a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
        //Sauve la position courante
        $x=$this->GetX();
        $y=$this->GetY();
        //Dessine le cadre
        $this->Rect($x,$y,$w,$h);
        //Imprime le texte
        $this->MultiCell($w,5,$data[$i],0,$a);
        //Repositionne à droite
        $this->SetXY($x+$w,$y);
    }
    //Va à la ligne
    $this->Ln($h);
}

function CheckPageBreak($h)
{
    //Si la hauteur h provoque un débordement, saut de page manuel
    if($this->GetY()+$h>$this->PageBreakTrigger)
        $this->AddPage($this->CurOrientation);
}

function NbLines($w,$txt)
{
    //Calcule le nombre de lignes qu'occupe un MultiCell de largeur w
    $cw=&$this->CurrentFont['cw'];
    if($w==0)
        $w=$this->w-$this->rMargin-$this->x;
    $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
    $s=str_replace("\r",'',$txt);
    $nb=strlen($s);
    if($nb>0 and $s[$nb-1]=="\n")
        $nb--;
    $sep=-1;
    $i=0;
    $j=0;
    $l=0;
    $nl=1;
    while($i<$nb)
    {
        $c=$s[$i];
        if($c=="\n")
        {
            $i++;
            $sep=-1;
            $j=$i;
            $l=0;
            $nl++;
            continue;
        }
        if($c==' ')
            $sep=$i;
        $l+=$cw[$c];
        if($l>$wmax)
        {
            if($sep==-1)
            {
                if($i==$j)
                    $i++;
            }
            else
                $i=$sep+1;
            $sep=-1;
            $j=$i;
            $l=0;
            $nl++;
        }
        else
            $i++;
    }
    return $nl;
}
}

class PDF extends PDF_MySQL_Table
{

}


$pdf = new PDF_MC_Table();
$pdf->AddPage();
$pdf->SetWidths(array(24,30,48,25,15,18,18));
$pdf->SetFont('Arial','',10);
$pdf->SetAutoPageBreak(true,55); 

$pdf->Row(array("Marque","Ref_int", "Description", "N_Or/IMMAT","Qte","Prix U HT","Total HT"));
$sql2='select m.nom marque, 	ref_int as Reference, 	descriptif, 	ref_or as N_OR, FORMAT(qte,2) as Qte, 	FORMAT(prix_unitaire,2) as Prix, FORMAT((qte*prix_unitaire),2)  as totalht
FROM boncommande_article bca
INNER JOIN marque m ON m.id_marque=bca.id_marque
WHERE bca.id_bc="'.valid_data($id_bc).'"';

$query2= mysql_query($sql2) or die('erreur');
while ( $list2 = mysql_fetch_array( $query2 ) ) {
 $pdf->Row(array($list2["marque"],$list2["Reference"], $list2["descriptif"], $list2["N_OR"], $list2["Qte"], $list2["Prix"], $list2["totalht"]));
		//$pdf->Row(array($list2["service"],$list2["marque"],$list2["Reference"], $list2["descriptif"], $list2["N_OR"], $list2["Qte"], $list2["Prix"]));
			
		}


	$pdf->Output("boncommande-".$list0["id_bc"]. ".pdf","F"); 
}





}
ci-dessus une fonction que j'essai de creer.

La fonction est de générer un fichier PDF (avec fpdf et des class fdpi ,etc.)

1- Je ne sais pas si ma fonction est bien construitre?
2- Les variable de ma requete sql ($list0) ne passe pas dans les fonction header footer?

Pourriez-vous m'aiguiller , m'expliquer la démarche pour faire fonctionner cette fonction. Ou bien m'indiquer si je suis mal partie.

Merci d'avance pour votre aide

guigui69