...

View Full Version : Minimum Check Out Price, Round Up?



reyna12
12-21-2006, 03:54 PM
If the amount of slots entered amounts to less than 5 is it possible to round up the amount of slots until it equals 5 or above? There is also another conditional statement of 10 or more slots.

Also: I am not the most talented of coders so there may be other ways or errors in the script elsewhere.



<?php

if($_POST['calculate']) {

// Set Minimum Slots
$min = "10";

// Set Minimum Price
$minp = "5.00";

// Get Bitrate Sent From Form
$bitrate = $_POST['bitrate'];

// Get Amount Of Slots Sent From Form
$slots = $_POST['slots'];

if($slots<$min)
{
$slots = "10";
}

switch($bitrate)
{
case "32000": // 32kbps
$slot = "0.18"; // Price for one slot
break;
case "40000": // 40kbps
$slot = "0.22"; // Price for one slot
break;
case "48000": // 48kbps
$slot = "0.29"; // Price for one slot
break;
case "56000": // 56kbps
$slot = "0.34"; // Price for one slot
break;
case "64000": // 64kbps
$slot = "0.42"; // Price for one slot
break;
case "80000": // 80kbps
$slot = "0.51"; // Price for one slot
break;
case "96000": // 96kbps
$slot = "0.67"; // Price for one slot
break;
case "112000": // 112kbps
$slot = "0.78"; // Price for one slot
break;
case "128000": // 128kbps
$slot = "0.84"; // Price for one slot
break;
case "144000": // 144kbps
$slot = "0.99"; // Price for one slot
break;
case "160000": // 160kbps
$slot = "1.08"; // Price for one slot
break;
case "192000": // 192kbps
$slot = "1.19"; // Price for one slot
break;
case "224000": // 224kbps
$slot = "1.58"; // Price for one slot
break;
case "256000": // 256kbps
$slot = "1.87"; // Price for one slot
break;
case "320000": // 320kbps
$slot = "2.00"; // Price for one slot
break;

default: // Ignore
$slot = "0.00"; // Ignore
break;
}

$total = $slot * $slots;

if($total<$minp)
{

// Need Help Here

}
}
?>

<html>
<head>
<title>Shoutcast Calc</title>
</head>
<body>
<form name="shoutcast" method="post" action="<? $_POST['PHP_Self']; ?>">
<table width="40%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Bit Rate:</td>
<td>
<select name="bitrate">
<option value="32000">32kbps</option>
<option value="40000">40kbps</option>
<option value="48000">48kbps</option>
<option value="56000">56kbps</option>
<option value="64000">64kbps</option>
<option value="80000">80kbps</option>
<option value="96000">96kbps</option>
<option value="112000">112kbps</option>
<option value="128000">128kbps</option>
<option value="144000">144kbps</option>
<option value="160000">160kbps</option>
<option value="192000">192kbps</option>
<option value="224000">224kbps</option>
<option value="256000">256kbps</option>
<option value="320000">320kbps</option>
</select>
</td>
</tr>
<tr>
<td>Slots Required: </td>
<td><input name="slots" type="text" size="10" maxlength="6"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="calculate" value="Calculate"></td>
</tr>
</table>
</form>
<?
if($total=="0.00")
{
}
else
{
echo "Slots: ".$slots."<br>";
echo "Cost: ".$total."";
}
?>
</body>
</html>

whizard
12-21-2006, 04:51 PM
doesn't



if ($slot < $min)
{
$slot = $min;
}


HTH
Dan

whizard
12-21-2006, 04:51 PM
Sorry, double post, my bad!

(Hey, 1 double post in 2 years and ~430 post isn't THAT bad..)

Dan

reyna12
12-21-2006, 05:10 PM
That just sets it so when they enter less than 10 slots if rounds it up to 10 but i also want it so if they enter an amount of slots amounting to less than a total of 5.00 it should round the slots up to a number that's either 5.00 or above.

Am i better off adding a minimum for each bitrate (selection)



case "32000": // 32kbps
$slot = "0.18"; // Price for one slot
$min = "28";
break;


http://yuxxi.com/calc.php

whizard
12-21-2006, 05:31 PM
I'm having trouble understanding

it should round the slots up to a number that's either 5.00 or above.

How do you know whether you want it to round up to 5.00 or up to something above?

Dan

reyna12
12-21-2006, 05:46 PM
The minimum order price is $5.00 so if someone enters a quantity which amounts to less than $5.00 it should round up the quantity until it does.

Hope that's easier

dumpfi
12-21-2006, 05:58 PM
Try this:
<?php
$bitRates = array(
'32000' => 0.18,
'40000' => 0.22,
'48000' => 0.29,
'56000' => 0.34,
'64000' => 0.42,
'80000' => 0.51,
'96000' => 0.67,
'112000' => 0.78,
'128000' => 0.84,
'144000' => 0.99,
'160000' => 1.08,
'192000' => 1.19,
'224000' => 1.58,
'256000' => 1.87,
'320000' => 2.00,
'default' => 0
);

if(isset($_POST['calculate']))
{
$minSlots = 10;
$minPrice = 5.0;

if(isset($_POST['bitrate']) && isset($bitRates[$_POST['bitrate']]))
{
$slotCost = $bitRates[$_POST['bitrate']];
}
else
{
$slotCost = $bitRates['default'];
}
if(isset($_POST['slots']) && $_POST['slots'] > $minSlots && $_POST['slots'] * $slotCost >= $minPrice)
{
$slots = $_POST['slots'];
}
else
{
$slots = max($minSlots, ceil($minPrice / $slotCost));
}

$total = $slotCost * $slots;
}
else
{
$total = 0.0;
}
?>

<html>
<head>
<title>Shoutcast Calc</title>
</head>
<body>
<form name="shoutcast" method="post" action="<?php echo getenv('PHP_SELF'); ?>">
<table width="40%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Bit Rate:</td>
<td>
<select name="bitrate">
<option value="32000">32kbps</option>
<option value="40000">40kbps</option>
<option value="48000">48kbps</option>
<option value="56000">56kbps</option>
<option value="64000">64kbps</option>
<option value="80000">80kbps</option>
<option value="96000">96kbps</option>
<option value="112000">112kbps</option>
<option value="128000">128kbps</option>
<option value="144000">144kbps</option>
<option value="160000">160kbps</option>
<option value="192000">192kbps</option>
<option value="224000">224kbps</option>
<option value="256000">256kbps</option>
<option value="320000">320kbps</option>
</select>
</td>
</tr>
<tr>
<td>Slots Required: </td>
<td><input name="slots" type="text" size="10" maxlength="6"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="calculate" value="Calculate"></td>
</tr>
</table>
</form>
<?php
if(0.0 != $total)
{
echo 'Slots: ',$slots,'<br>';
echo 'Cost: ',$total;
}
?>
</body>
</html>dumpfi

whizard
12-21-2006, 05:58 PM
Maybe like this.. (Changes in red)

<?php

if($_POST['calculate']) {

// Set Minimum Slots
$min = "10";

// Set Minimum Price
$minp = "5.00";

// Get Bitrate Sent From Form
$bitrate = $_POST['bitrate'];

// Get Amount Of Slots Sent From Form
$slots = $_POST['slots'];

if($slots<$min)
{
$slots = "10";
}

switch($bitrate)
{
case "32000": // 32kbps
$slot = "0.18"; // Price for one slot
break;
case "40000": // 40kbps
$slot = "0.22"; // Price for one slot
break;
case "48000": // 48kbps
$slot = "0.29"; // Price for one slot
break;
case "56000": // 56kbps
$slot = "0.34"; // Price for one slot
break;
case "64000": // 64kbps
$slot = "0.42"; // Price for one slot
break;
case "80000": // 80kbps
$slot = "0.51"; // Price for one slot
break;
case "96000": // 96kbps
$slot = "0.67"; // Price for one slot
break;
case "112000": // 112kbps
$slot = "0.78"; // Price for one slot
break;
case "128000": // 128kbps
$slot = "0.84"; // Price for one slot
break;
case "144000": // 144kbps
$slot = "0.99"; // Price for one slot
break;
case "160000": // 160kbps
$slot = "1.08"; // Price for one slot
break;
case "192000": // 192kbps
$slot = "1.19"; // Price for one slot
break;
case "224000": // 224kbps
$slot = "1.58"; // Price for one slot
break;
case "256000": // 256kbps
$slot = "1.87"; // Price for one slot
break;
case "320000": // 320kbps
$slot = "2.00"; // Price for one slot
break;

default: // Ignore
$slot = "0.00"; // Ignore
break;
}

$total = $slot * $slots;

if($total<$minp)
{
$difference = ($minp - $total);
$slots_to_add = ($difference/$slot);
$slots = $slots + $sots_to_add;
}
}
?>
<html>
<head>
<title>Shoutcast Calc</title>
</head>
<body>
<form name="shoutcast" method="post" action="<? $_POST['PHP_Self']; ?>">
<table width="40%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Bit Rate:</td>
<td>
<select name="bitrate">
<option value="32000">32kbps</option>
<option value="40000">40kbps</option>
<option value="48000">48kbps</option>
<option value="56000">56kbps</option>
<option value="64000">64kbps</option>
<option value="80000">80kbps</option>
<option value="96000">96kbps</option>
<option value="112000">112kbps</option>
<option value="128000">128kbps</option>
<option value="144000">144kbps</option>
<option value="160000">160kbps</option>
<option value="192000">192kbps</option>
<option value="224000">224kbps</option>
<option value="256000">256kbps</option>
<option value="320000">320kbps</option>
</select>
</td>
</tr>
<tr>
<td>Slots Required: </td>
<td><input name="slots" type="text" size="10" maxlength="6"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="calculate" value="Calculate"></td>
</tr>
</table>
</form>
<?
if($total=="0.00")
{
}
else
{
echo "Slots: ".$slots."<br>";
echo "Cost: ".$total."";
}
?>
</body>
</html>


HTH
Dan

reyna12
12-21-2006, 06:11 PM
Much Much Much Appreciated dumpfi, it works but unfortunately i have no idea how, guess i will have to learn arrays



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum