简体   繁体   English

fpdf while循环中的两个sql查询不起作用

[英]fpdf two sql queries in while loop doesnt work

I got a php Code using FPDF with three queries. 我得到了使用FPDF和三个查询的php代码。 The first query is working, but the other ones not. 第一个查询有效,而其他查询无效。 They are both together in a while loop. 他们在一起处于while循环中。 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. 谢谢你的帮助。

Unless I am missing something I would suggest you merge the 2 queries into 1 query as below: 除非我缺少任何东西,否则建议您将2个查询合并为1个查询,如下所示:

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



}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM