【发布时间】:2010-07-27 19:59:15
【问题描述】:
我们已经编写了这个 PHP 脚本:
function price($id)
{
$ergebnis = mysql_query("SELECT * FROM preiszuordnungen where id=$id");
while($row = mysql_fetch_object($ergebnis))
{
//Wenn grundpreis dann färben
if($row->typ=="grundpreis")
{
$gp="style=\"background-color: #FF22FF; color: #FFFFFF; padding: 5px;\"";
}
else
{
}
//preisfomat umändern
$preis="+ ".number_format($row->preis,2)." EUR";
$GLOBALS["$id"] = $row->preis;
//zeile ausgeben
echo"<div $gp class=\"rechnung_bezeichnung\">$row->bezeichnung</div><div $gp class=\"rechnung_preis\">$preis</div><p style=\"clear: both;\">";
}
}
我们的问题是我们不能使用这个函数之外的变量。在我们的脚本中,我们需要这样的函数:
$preis=price(101);
$preis=price(909);
...
现在我们要对函数的输出求和。变量 $row->price
如果有人可以帮助我们,我们很高兴。
【问题讨论】:
标签: php function sum while-loop