Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

117
Vistas
fpdf two sql queries in while loop doesnt work

I got a php Code using FPDF with three queries. The first query is working, but the other ones not. They are both together in a while loop. The crazy thing about it is, that I get just sometimes results.

Here is the Code:

while($result3 = mysql_fetch_assoc($query3)) {

    $pdf->Cell(9, 8, $result3['ID'], 1);
    $pdf->Cell(17, 8, $result3['Tag'], 1);
    $pdf->Cell(20, 8, $result3['date'], 1);
    $pdf->Cell(25, 8, $result3['starttime'], 1);
    $pdf->Cell(25, 8, $result3['place'], 1);
    $pdf->Cell(25, 8, $result3['player'], 1);
    $pdf->Cell(35, 8, $result3['ref'], 1);
    $pdf->Cell(15, 8, $result3['art'], 1);
    $pdf->Ln(8);

    $players = $result3['player'];
    $pdf->players =$players;
    $teile = explode(" ", $players);
    $player1 = $teile[0];
    $player2 = $teile[2];
    $pdf->player1 = $player1;
    $pdf->player2 = $player2;

    $pdf->Ln(8);

    $abfrage2 = "(SELECT * 
    FROM  `$liste` 
    WHERE  `$Art` =  '$player1')";
    $ergebnis2 = mysql_query($abfrage2);

    $abfrage3 = "(SELECT * 
    FROM  `$liste` 
    WHERE  `$Art` =  '$player2')";
    $ergebnis3 = mysql_query($abfrage3);

    #PLayer werden ausgegeben
    $pdf->Cell(15, 8, $pdf->player1, 1);
    $pdf->Cell(15, 8, $pdf->player2, 1);
    $pdf->Ln(8);

    while($row2 = mysql_fetch_array($ergebnis2) and $row3 = mysql_fetch_array($ergebnis3)){
        $pdf->Cell(30, 8, $row2['Vorname'], 1);
        $pdf->Cell(30, 8, $row2['Name'], 1);
        $pdf->Cell(30, 8, $row3['Vorname'], 1);
        $pdf->Cell(30, 8, $row3['Name'], 1);
        $pdf->Cell(9, 8, "  ", 1);
        $pdf->Ln(8);
    }


    $pdf->Ln(8);



}

Thanks for your help.

8 months ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Unless I am missing something I would suggest you merge the 2 queries into 1 query as below:

while($result3 = mysql_fetch_assoc($query3)) {

    $pdf->Cell(9, 8, $result3['ID'], 1);
    $pdf->Cell(17, 8, $result3['Tag'], 1);
    $pdf->Cell(20, 8, $result3['date'], 1);
    $pdf->Cell(25, 8, $result3['starttime'], 1);
    $pdf->Cell(25, 8, $result3['place'], 1);
    $pdf->Cell(25, 8, $result3['player'], 1);
    $pdf->Cell(35, 8, $result3['ref'], 1);
    $pdf->Cell(15, 8, $result3['art'], 1);
    $pdf->Ln(8);

    $players = $result3['player'];
    $pdf->players =$players;
    $teile = explode(" ", $players);
    $player1 = $teile[0];
    $player2 = $teile[2];
    $pdf->player1 = $player1;
    $pdf->player2 = $player2;

    $pdf->Ln(8);

    $abfrage2 = "SELECT 
         L1.`Vorname` as Vorname_L1, 
         L1.`Name` as Name_L1,
         L2.`Vorname` as Vorname_L2, 
         L2.`Name` as Name_L2
         FROM   
        (SELECT *  FROM  `$liste` WHERE  `$Art` =  '$player1') L1,
        (SELECT *  FROM  `$liste` WHERE  `$Art` =  '$player2') L2";
    $ergebnis2 = mysql_query($abfrage2);



    #PLayer werden ausgegeben
    $pdf->Cell(15, 8, $pdf->player1, 1);
    $pdf->Cell(15, 8, $pdf->player2, 1);
    $pdf->Ln(8);

    while($row2 = mysql_fetch_array($ergebnis2)){
        $pdf->Cell(30, 8, $row2['Vorname_L1'], 1);
        $pdf->Cell(30, 8, $row2['Name_L1'], 1);
        $pdf->Cell(30, 8, $row2['Vorname_L2'], 1);
        $pdf->Cell(30, 8, $row2['Name_L2'], 1);
        $pdf->Cell(9, 8, "  ", 1);
        $pdf->Ln(8);
    }


    $pdf->Ln(8);



}
8 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos