基本的なPHPフォームのヘルプ(通貨表示)
質問
あなたたちは昨日とても役に立ちました。私はまだここで少し混乱しています。
右端の列の数値が最も近いドルに四捨五入されるようにしたい:
http://www.nextadvisor.com /voip_services/voip_calculator.php?monthlybill=50&Submit=Submit
テーブルのコードは次のようになります:
$ offer [1,2,3,4,5,6,7] calcsavingsannを丸めたいのですが、どうすればよいですか
<table width="100%;" border="0" cellspacing="0" cellpadding="0"class="credit_table2" >
<tr class="credit_table2_brd">
<td class="credit_table2_brd_lbl" width="100px;">Services:</td>
<td class="credit_table2_brd_lbl" width="120px;">Our Ratings:</td>
<td class="credit_table2_brd_lbl" width="155px;">Monthly VoIP Bill:</td>
<td class="credit_table2_brd_lbl" width="155px;">Annual Savings:</td>
</tr>
<?php
$offer1price="24.99";
$offer2price="20.00";
$offer3price="21.95";
$offer4price="23.95";
$offer5price="19.95";
$offer6price="23.97";
$offer7price="24.99";
$offer1calcsavings= $monthlybill - $offer1price;
$offer2calcsavings= $monthlybill - $offer2price;
$offer3calcsavings= $monthlybill - $offer3price;
$offer4calcsavings= $monthlybill - $offer4price;
$offer5calcsavings= $monthlybill - $offer5price;
$offer6calcsavings= $monthlybill - $offer6price;
$offer7calcsavings= $monthlybill - $offer7price;
$monthybill="monthlybill";
$offer1calcsavingsann= $offer1calcsavings * 12;
$offer2calcsavingsann= $offer2calcsavings * 12;
$offer3calcsavingsann= $offer3calcsavings * 12;
$offer4calcsavingsann= $offer4calcsavings * 12;
$offer5calcsavingsann= $offer5calcsavings * 12;
$offer6calcsavingsann= $offer6calcsavings * 12;
$offer7calcsavingsann= $offer7calcsavings * 12;
$re=1;
$offer ='offer'.$re.'name';
$offername= ${$offer};
while($offername!=""){
$offerlo ='offer'.$re.'logo';
$offerlogo=${$offerlo};
$offerli ='offer'.$re.'link';
$offerlink=${$offerli};
$offeran ='offer'.$re.'anchor';
$offeranchor=${$offeran};
$offerst ='offer'.$re.'star1';
$offerstar=${$offerst};
$offerbot='offer'.$re.'bottomline';
$offerbottomline=${$offerbot};
$offerca ='offer'.$re.'calcsavings';
$offercalcsavings=${$offerca};
$offerpr ='offer'.$re.'price';
$offerprice=${$offerpr};
$offersavann ='offer'.$re.'calcsavingsann';
$offercalcsavingsann=${$offersavann};
echo '<tr >
<td >
<a href="'.$offerlink.'" target="blank"><img src="http://www.nextadvisor.com'.$offerlogo.'" alt="'.$offername.'" />
</a>
</td>
<td ><span class="rating_text">Rating:</span>
<span class="star_rating1">
<img src="http://www.nextadvisor.com'.$offerstar.'" alt="" />
</span>
<br />
<div style="margin-top:5px; color:#0000FF;">
<a href="'.$offerlink.'" target="blank">Go to Site</a>
<span style="margin:0px 7px 0px 7px;">|</span><a href="'.$offeranchor.'">Review</a>
</div> </td>
<td >$'.$offerprice.'</td>
<td >$'.$offercalcsavingsann.'</td>
</tr>';
$re=$re+1;
$offer ='offer'.$re.'name';
$offername= ${$offer};
}
?>
</table>
他のヒント
Grepsedawkの答えは良いです。追加する唯一のことは、たとえば336.6ドルを表示するのではなく、 number_format を使用して$ 336.60を出力できることです。 。
(これはあなたの質問ではないことはわかっていますが、リンクを見ると、あなたにとって役立つかもしれないと思いました。)
編集-代わりに money_format を提案してくれたAndyに感謝します。
money_format()
は、フォーマットされた数値の文字列値を返す関数です。書式と、明らかに番号を制御できます。簡単な例として、変数$myNumber
に値がある場合、その結果を特定のテーブルのデータセルに組み込むことができます;
<?php echo ("<td>".money_format('%n',$myNumber)."</td>"); ?>
そして、すべての値に対してこれを行う必要があります。すべての値が配列にある場合は、for
ループを介して。ここのn
はフォーマットオプションの1つです。いくつかあります。参照するのに適した場所は、PHP Webページ http:/です。 /au2.php.net/manual/en/function.money-format.php
これがお役に立てば幸いです。
使用方法を正しく理解できないようです。エコーの使用方法は
echo '<tr >
<td ><a href="'.$offerlink.'" target="blank"><img src="http://www.nextadvisor.com'.$offerlogo.'" alt="'.$offername.'" /></a></td>
<td ><span class="rating_text">Rating:</span><span class="star_rating1"><img src="http://www.nextadvisor.com'.$offerstar.'" alt="" /></span><br />
<div style="margin-top:5px; color:#0000FF;"><a href="'.$offerlink.'" target="blank">Go to Site</a><span style="margin:0px 7px 0px 7px;">|</span><a href="'.$offeranchor.'">Review</a></div> </td>
<td >$'.$offerprice.'</td>
<td >$'.$offercalcsavingsann.'</td>
</tr>';
<!> quot; set locale <!> quot;
"<?php"
は。私はそれを書く方法を理解していません、そして私がするすべての方法はエラーを返します。