2012-04-09 40 views
2

我需要在表格數組輸出中舍入一個sql循環的結果。想不通的語法...如何在一個表格輸出中舍入mysql列

$result = mysql_query("SELECT `Energ_Kcal`*`yield`*`qty` AS `cal` FROM allinnot a 
WHERE `own_id` = $user->id"); 

    echo "<tr><td>" . $row['Shrt_Desc'] . "</td><td>&nbsp;" . $row['desc'] . "</td><td>" . $row['cal'] . " cal</td></tr>"; 

cal返回與超越小數許多數字的值。我只需要它來顯示一個整數的四捨五入整數。我嘗試了ROUND(),但是我必須把它放在錯誤的地方。

回答

3

一般語法

ROUND(expression, 2) 
+0

哎,謝謝!我正在嘗試用AS'cal'進行內部輪迴。 ROUND('Energ_Kcal' *'yield' *'qty')AS'cal'完美運作。 – Nat 2012-04-09 19:40:09

2

一輪應該去周圍的價值觀,試試這個:

$result = mysql_query("SELECT ROUND(`Energ_Kcal`*`yield`*`qty`,2) AS `cal` FROM allinnot a 
WHERE `own_id` = $user->id"); 

    echo "<tr><td>" . $row['Shrt_Desc'] . "</td><td>&nbsp;" . $row['desc'] . "</td><td>" . $row['cal'] . " cal</td></tr>"; 
相關問題