Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
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.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

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);



}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!