如何:使用 PHP 格式化带有货币符号的 MySQL 查询结果
我有一个 MySQL 查询,它从表中获取数值 VARCHAR (20)
,我需要格式化结果以包含千位分隔符 (,
) 和小数分隔符 ( .
) 到两个位置。
我已经搜索了很多简单的查询,所以现在我想知道使用 CSS 是否可以实现这一点。
这是表数据:
Income ------------------- 1234456789 234456000 987456000
等等。这是查询:
// Fetch data
$sql="SELECT * FROM scoreboard WHERE codcliente = '".$q."' OR nombre LIKE '%".$q."%'";
$result = mysql_query($sql);
if(mysql_num_rows($result) == 0){
echo '<div align="center" style="background-color:#CCCCCC; font-weight:bold; color:#C0504D;">Record no existe. <input id="srchcreate" type="button" value="Crear" /></div>';
return;
}
//echo $result;
结果:
// Construct the table
echo "<table>";
// Construct the array
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['codcliente'] . "</td>";
echo "<td>" . $row['nombre'] . "</td>";
// echo "<td>" . $row['ejecutivo'] . "</td>";
// echo "<td>" . $row['banca_as400'] . "</td>";
// echo "<td>" . $row['banca_real'] . "</td>";
// echo "<td>" . $row['ingresos'] . "</td>";
echo "<td>" . $row['ciiu'] . "</td>";
// echo "<td>" . $row['division'] . "</td>";
echo "<td>" . $row['actividad'] . "</td>";
echo "<td>" . $row['riesgo_industria'] . "</td>";
echo "<td>" . $row['riesgo_cliente'] . "</td>";
echo "<td>" . $row['fecha'] . "</td>";
echo "<td>" . $row['analista'] . "</td>";
echo "</tr>";
}
echo "</table>";
这将被插入到 PHP 文件中并显示为表格。
I have a MySQL query that fetches a numeric value VARCHAR (20)
from a table, and I need to format the result to include thousands separators (,
) and decimal separators (.
) to two positions.
I've searched a lot for a simple query, so now I want to know if this is possible using CSS.
Here is the table data:
Income ------------------- 1234456789 234456000 987456000
And so on. Here's the query:
// Fetch data
$sql="SELECT * FROM scoreboard WHERE codcliente = '".$q."' OR nombre LIKE '%".$q."%'";
$result = mysql_query($sql);
if(mysql_num_rows($result) == 0){
echo '<div align="center" style="background-color:#CCCCCC; font-weight:bold; color:#C0504D;">Record no existe. <input id="srchcreate" type="button" value="Crear" /></div>';
return;
}
//echo $result;
And the result:
// Construct the table
echo "<table>";
// Construct the array
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['codcliente'] . "</td>";
echo "<td>" . $row['nombre'] . "</td>";
// echo "<td>" . $row['ejecutivo'] . "</td>";
// echo "<td>" . $row['banca_as400'] . "</td>";
// echo "<td>" . $row['banca_real'] . "</td>";
// echo "<td>" . $row['ingresos'] . "</td>";
echo "<td>" . $row['ciiu'] . "</td>";
// echo "<td>" . $row['division'] . "</td>";
echo "<td>" . $row['actividad'] . "</td>";
echo "<td>" . $row['riesgo_industria'] . "</td>";
echo "<td>" . $row['riesgo_cliente'] . "</td>";
echo "<td>" . $row['fecha'] . "</td>";
echo "<td>" . $row['analista'] . "</td>";
echo "</tr>";
}
echo "</table>";
This gets inserted to a PHP file and displayed as a table.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,CSS 并不是为此而设计的。
JavaScript 确实有这个能力。
No, CSS isn't designed to do that.
JavaScript does have that capability.
123,456,789.00
123,456,789.00