如何根据另一个字段的值回显字段? 我希望我的剧本可以告诉你我想要的东西。
$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);
答案 0 :(得分:1)
这是遍历整个结果的问题吗?
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
if ($row["currency"] == "USD") echo $row["amount"];
}
答案 1 :(得分:1)
尝试:
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
if (strstr($row["amount"], 'USD) !== FALSE)
echo $row["amount"];
}
答案 2 :(得分:0)
它应该只是一个例子:
$sth = $conn->prepare("SELECT * FROM table WHERE item = '$item'");
$sth->execute();
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
if ($row['currency'] == 'USD') {
echo $row['amount'];
}
虽然这假设if语句上面的代码正确地获取数据库结果,但我不能惭愧地说,我仍然使用已弃用的mysql_*
函数。