以PHP&;为单位计算每件物品的数量成本;MySQL
我正在制作一个名为“街头暴徒”的基于文本的角色扮演游戏,我正在编写黑市页面,这个页面现在已经完成,除了我想根据用户销售的数量计算每件商品的价格之外 例如,“Ryan以500000000美元的价格出售了5个信用卡”-现在我想要一个PHP算法告诉我,这些信用卡每件价值100000000美元。。。。我不认为我能更好地解释这一点,但任何帮助都将不胜感激。。。(我还附上了一张照片,试图更好地解释这一点……)以PHP&;为单位计算每件物品的数量成本;MySQL,php,mysql,regex,Php,Mysql,Regex,我正在制作一个名为“街头暴徒”的基于文本的角色扮演游戏,我正在编写黑市页面,这个页面现在已经完成,除了我想根据用户销售的数量计算每件商品的价格之外 例如,“Ryan以500000000美元的价格出售了5个信用卡”-现在我想要一个PHP算法告诉我,这些信用卡每件价值100000000美元。。。。我不认为我能更好地解释这一点,但任何帮助都将不胜感激。。。(我还附上了一张照片,试图更好地解释这一点……) 您没有尝试我帮助您启动的任何东西(并且想要使用regex): 写下你尝试过的东西。代码在哪里?这是
您没有尝试我帮助您启动的任何东西(并且想要使用regex):
写下你尝试过的东西。代码在哪里?这是一个帮助启动询问者的示例
<?
$query=mysql_query("SELECT * FROM blackmarket_credits ORDER BY id");
$nums =mysql_num_rows($query);
if ($nums == "0"){
echo "<tr><td colspan='6' align='center'>The market is currently empty!</td></tr>"; }
while($i = mysql_fetch_object($query)){
$blah =mysql_query("SELECT * FROM users WHERE username='$i->username'");
$users =mysql_fetch_object($blah);
if ($i->expires > time()){
$timeleft = $i->expires - time();
if ($i->username == "$username"){$show = "<img width='16px' height='16px' src='/images/icons/cross.png' onclick=\"window.location.href='?type=points&remove=$i->id'\">"; }elseif ($i->owner != "$username"){ $show = "<img width='16px' height='16px' src='/images/icons/tick.png' onclick=\"window.location.href='?type=points&buy=$i->id&id=$i->id'\">";}
if ($col=="0"){ $td="151515"; $col="1"; }else{ $td="000000"; $col="0"; }
echo "<tr style='background-color: #$td'>
<td valign='baseline' height='40'><br><div style='display: inline-block;z-index: 10;position: relative; width: 30px;height: 30px;'>
<img src='$users->avatar' width='30' height='30'>
<div style='position: absolute; bottom: 0px; right: 0px;'><img src='/images/blip_offline.png' width='10'></div>
</div> </td>
<td align='left' height='40'><a href=profile.php?viewuser=$i->username>$i->username</a></td>
<td align='left' height='40'>".number_format($i->quantity)." Credits</td>
<td align='left' height='40'>$".number_format($i->cost)."<br><span style='color:#777'>$".number_format($THIS IS WHAT I'M ATTEMPTING TO GET)." per item</span></td>
<td align='left' height='40'><span id='timer1'></span><script type='text/javascript'>setTimer('timer1','$timeleft', { 0: function () { window.location = 'black_market.php' }}); </script></td>
<td align=center height='40'>$show</td></tr>"; }} ?>
function calcCostPerItem($totalPrice, $quantityItems) {
return preg_replace("/\D(\d+).(\d+).(\d+).(\d+)/", "$1$2$3$4", $totalPrice) / $quantityItems;
}
echo calcCostPerItem('$500.000.000.000', 5); //result 100000000000