Jump to content

Recommended Posts

You could allocate on a straight line. If qty is 10000, price is 25 each, if 1 then 300 each

[pre]

  300+  \

    |  \

    |    \

  150+    .\

    |    . \

    |    .  \

  25+    .  \

        +-+----+--

      1  .    10000

          .

          2000 = 245

         

          P = -275 * Q  + 300

              --------

                10000

[/pre]

 

<?php
function price ($q)
{
    
    return ceil($q * -275 / 10000) + 300;
}

for ($i = 0; $i <= 10000; $i+=1000) 
{
    $q = $i==0 ? 1 : $i;
    echo "$q :" . price($q) . '<br>';
}  

-->
1      :300
1000 :273
2000 :245
3000 :218
4000 :190
5000 :163
6000 :135
7000 :108
8000 :80
9000 :53
10000 :25

Link to comment
https://forums.phpfreaks.com/topic/78567-fluctuation/#findComment-397672
Share on other sites

Any value from 1 to 10000.

 

If it's 20,000 you pay them 250 to take them away :)

 

 

try it!

 

<?php
function price ($q)
{
    
    return ceil($q * -275 / 10000) + 300;
}

$qtys = array(1, 333, 659, 1000, 5000, 10000);
foreach ($qtys as $q) 
{
    echo "$q :" . price($q) . '<br>';
}  

/*
-->
1 :300
333 :291
659 :282
1000 :273
5000 :163
10000 :25
*/
?>

Link to comment
https://forums.phpfreaks.com/topic/78567-fluctuation/#findComment-398062
Share on other sites

Barand i can't thank you enough mate.. thanks for the help i ended up with

<?
include('config.php');
$q2 = mysql_fetch_row(mysql_query("SELECT SUM(drugs) FROM players;"));
function price ($q)
{
    
    return ceil($q * -275 / 20000) + 300;
}

$qtys = $q2;
foreach ($qtys as $q) 
{
    echo "$q :" . price($q) . '<br>';
}  
mysql_query('UPDATE players SET drugs = drugs + (drugfact*20), dpayout = (drugfact*20);');
mysql_query('UPDATE players SET credits = credits - (employees*wages)');
$sql = "UPDATE price SET cost = $q where ITEM = 'drugs'";
mysql_query($sql) or
  die($sql . ' : ' . mysql_error());
?>

 

works a treat!!

Link to comment
https://forums.phpfreaks.com/topic/78567-fluctuation/#findComment-398068
Share on other sites

Any var name you like (meaningful ones are best)

 

<?php
function price ($q)
{
    if ($q > 10000) return 25;
    return ceil($q * -275 / 10000) + 300;
}

$res = mysql_query("SELECT SUM(product) FROM players");
$quantity = mysql_result($res, 0);

echo 'Qty : ' . $quantity . ' at ' . price($quantity) . ' each';

?>
  

Link to comment
https://forums.phpfreaks.com/topic/78567-fluctuation/#findComment-398070
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.