2014-07-24 107 views
-1

美好的一天!我有一個總報告表,我想從GETT數據庫中的值和數字的格式,並有一個像這樣PHP 10,000.00輸出不喜歡這個php echo貨幣格式加上金額

這裏是我的審判PHP代碼。我有一張用於打印總報告的表格,並在格式化總金額時遇到問題。

function printpage() 
{ 
window.print() 
} 

</script></head> 
<body> 
<br> 
<br> 
<div class="container"> 
<center> 
<div class="alert alert-success" align="center"><h1>TOTAL REPORT</h1></div> 
<br /> 
<table class="table table-striped table-bordered" border="1" width="900"> 
    <thead> 
     <tr> 
      <th>First Name</th> 
      <th>Last Name</th> 
      <th>Address</th> 

      <th>Start of Event</th> 
      <th>End of Event</th> 
      <th>Quantity</th> 
      <th>Amount</th> 
      <th>Status</th> 
      <th>Confirmation</th>    
     </tr> 
    </thead> 
    <tbody> 
     <?php 
     $con=mysql_connect("localhost","root","")or die(mysql_error()); 
     $db=mysql_select_db('pm')or die(mysql_error()); 

      $query=mysql_query("select * from reservation ")or die(mysql_error()); 
      while($row=mysql_fetch_array($query)){ 
      $id=$row['id']; 
     ?> 
     <tr> 
      <?php $row['id'] ?> 
      <td><?php echo $row['firstname'] ?></td> 
      <td><?php echo $row['lastname'] ?></td> 
      <td><?php echo $row['address'] ?></td> 
      <td><?php echo $row['arrival']?></td> 
      <td><?php echo $row['departure'] ?></td> 
      <td><?php echo $row['result'] ?></td> 

      <td><?php 
      $number = 'payable'; 
      $payable = 0; 
      setlocale(LC_MONETARY,"en_PHP"); 
    echo $row("The price is %i", $payable); 
    ?> </td> 
      <td><?php echo $row['status'] ?></td> 
      <td><?php echo $row['confirmation'] ?></td> 
     </tr> 
     <?php } ?> 
    </tbody> 
</table> 
<?php 
    $result = mysql_query("SELECT sum(payable) FROM reservation") or die(mysql_error()); 
    while ($rows = mysql_fetch_array($result)) { 
?> 

<?php } 

$result1 = mysql_query("SELECT result(qty) FROM rooinventory") or die(mysql_error()); 
while ($rows1 = mysql_fetch_array($result1)) { 
?> 
<div class="pull-right"> 
    <div class="span"> 
     <div class="alert alert-info"><i class="icon-credit-card icon-large">  </i>&nbsp;Total Amount:&nbsp;<?php echo $rows1['sum(p)']; ?></div> 
    </div> 
</div> 
</center> 
<?php } ?> 
+0

mysql已棄用,請使用mysqli或PDO。 –

回答

0

您的區域設置是錯誤的,$數量實際上應該是$行值。

setlocale(LC_MONETARY, 'en_US'); 
echo money_format('%i', $row['payable']); 

對於Windows機器

echo '$' . number_format(floatval($row['payable'])); 
+0

但該號碼在我的表格行中應付。我想在那裏獲得號碼並在我的打印中使用格式 –

+0

如果您在從數據庫獲取價值時遇到問題,那麼答案與如何格式化該號碼無關。您需要從您的表中獲取該行並以$ row ['payable']的形式訪問。它似乎不像你的問題格式良好。如果你的問題實際上是從數據庫表中檢索一個值,那麼格式不會幫助你到達那裏。 – Zombiesplat

+0

是不是可能? –

0

您的代碼需要加以固定。另外en_US可能還不夠,具體取決於您的系統(即:Debian需要en_US.utf-8):

setlocale(LC_MONETARY, "en_US.utf-8"); 
echo money_format("The price is %i", $row['payable']); 
+0

這個數字在我的表格中我只想要一個格式並且有錢標記 –

+0

如果它在你的表格中,看着你的代碼,你可以像我編輯的例子那樣得到它。但我擔心我不知道名爲「en_PHP」的語言環境,但這可能無法工作。另一方面,如果您的查詢中「select * from reservation」中沒有「應付」,那麼您可能應該詢問關於查詢本身的內容,正如@ alan-asher告訴你的那樣。 – fpietka

+0

我已在我的表中支付。如果這是不可能的,我想回復PHP +應付。它將如何? –