计算每个项目从PHP中的数量中花费的金额和数量。 MySQL的

时间:2015-11-21 12:42:13

标签: php mysql regex

我正在制作一个名为Street-Thugs的基于文本的角色扮演游戏,我目前正在编写Black Market页面,此页面现已完成,除了我想要根据每个项目的价格计算每个项目的价格用户销售的数量......

EG。 “Ryan以500,000,000美元的价格出售5个积分” - 现在我想要一个PHP算法告诉我每个项目的价格为100,000,000美元......我认为我不能更好地解释这一点,但是任何帮助都会非常感激。 ..(我还附上了一张图片,试着更好地解释一下......)Image of Black Market Table

<? 

$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> &nbsp; </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'>&dollar;".number_format($i->cost)."<br><span style='color:#777'>&dollar;".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>"; }}  ?>

1 个答案:

答案 0 :(得分:0)

你没有尝试任何我帮助你开始(并想使用正则表达式):

    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