如何根据另一个字段的值回显一个字段?我希望我的脚本能以某种方式告诉你我想要什么。
$sth = $conn->prepare("SELECT * FROM table WHERE item = '$item'");
$sth->execute();
$row = $sth->fetch(PDO::FETCH_ASSOC);
echo ($row['amount'] WHERE $row['currency'] = 'USD');
这是我根据您的想法创建的脚本。但是对我来说,它必须如此愚蠢仍然没有意义。带有 $pdf 的底部脚本可以忽略。
foreach($conn->query("SELECT amount FROM stockpricetable WHERE itemrelation = '$row[itemnumber]'") as $row2) {
if ($row2['exchange'] == '') { $DKK = $row2['amount'];}
if ($row2['exchange'] == 'CHF') { $CHF = $row2['amount'];}
if ($row2['exchange'] == 'EUR') { $EUR = $row2['amount'];}
if ($row2['exchange'] == 'GBP') { $GBP = $row2['amount'];}
if ($row2['exchange'] == 'SEK') { $SEK = $row2['amount'];}
if ($row2['exchange'] == 'USD') { $USD = $row2['amount'];}
}
$pdf->Text(26, 4, 'DKK'.$DKK);
$pdf->Text(26, 8, 'EUR'.$EUR);
$pdf->Text(26, 12, 'GBP'.$GBP);
$pdf->Text(46, 4, 'SEK'.$SEK);
$pdf->Text(46, 8, 'CHF'.$CHF);
$pdf->Text(46, 12, 'USD'.$USD);