我使用FPDF获得了一个带有三个查询的PHP代码。第一个查询正在运行,但其他查询没有。它们都在一起循环。关于它的疯狂之处在于,我有时会得到结果。
以下是代码:
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);
}
感谢您的帮助。
答案 0 :(得分:1)
除非我遗漏了某些内容,否则我建议您将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);
}