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 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀