doukeng7426 2016-04-03 01:28
浏览 17
已采纳

在PHP中返回格式化的数字

I am trying to get a number value that is pulled from a mysql database to be formatted differently in a php document.

        $oIteminfo = mysql_query("
    SELECT Items.PartID, Items.VendorCost, Items.ProductName, Sum(Sales.AmountSold) AS SumOfAmountSold
    FROM Items 
    LEFT JOIN Sales 
    ON Items.PartID = Sales.PartID
    GROUP BY Items.PartID, Items.VendorCost, Items.ProductName
    HAVING Items.PartID=$iPartID;


") or die(mysql_error()); 


while($row = mysql_fetch_array($oIteminfo)) 
    { 
    ECHO "<h1>WOWAuctionSales</h1>";
    ECHO "<img src=\"http://www.wowauctionsales.com/images/".$iPartID.".jpg\"height='35' width='35'>";
    ECHO "<h1>".$row['ProductName']."</h1><br>";  
    ECHO "<B>Total Sold:</B>".$row['SumOfAmountSold']."<br>";
    ECHO "<B>Vendor Price:</B>".$row['VendorCost']."<br>";

For example in one instance the result will pull the following number 162356 I want that number to be formatted to say 16g 23s 56c or 00g 00s 00c I have looked a fprintf, sprintf and printf, but they do not seem to do the trick. I have seen this formatting done before in php but I cannot seem to figure it out how to do it myself.

  • 写回答

1条回答 默认 最新

  • dongnao9525 2016-04-03 01:38
    关注

    i can think of a dozen options here is one

    //$number ="162356";
    $number =$row['VendorCost'];
    echo substr($number,0,2).'g '.substr($number,2,2).'s '.substr($number,4,2).'c';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算