Brian J Kirk
Brian J Kirk

Reputation: 61

Returning a Formatted Number in 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.

Upvotes: 0

Views: 37

Answers (1)

user557846
user557846

Reputation:

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';

Upvotes: 1

Related Questions