我正试图获得一个从mysql数据库中提取的数值,以便在php文档中以不同的格式进行格式化。
$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>";
例如,在一个例子中,结果将拉取以下数字162356。我希望将该数字格式化为16g 23s 56c或00g 00s 00c。我看过fprintf、sprintf和printf,但它们似乎没有起到作用。我以前在php中看到过这种格式化,但我似乎不知道如何自己完成。
我能想到十几个选项,这里是一个
//$number ="162356";
$number =$row['VendorCost'];
echo substr($number,0,2).'g '.substr($number,2,2).'s '.substr($number,4,2).'c';