Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jan 2006
    Posts
    88
    Thanks
    4
    Thanked 1 Time in 1 Post

    Minimum Check Out Price, Round Up?

    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.

    Code:
    <?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>
    Last edited by reyna12; 12-21-2006 at 03:56 PM.

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    doesn't

    PHP Code:
    if ($slot $min)
     {
      
    $slot $min;
     } 
    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Sorry, double post, my bad!

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

    Dan
    Last edited by whizard; 12-21-2006 at 05:30 PM.
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #4
    New Coder
    Join Date
    Jan 2006
    Posts
    88
    Thanks
    4
    Thanked 1 Time in 1 Post
    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)

    PHP Code:
        case "32000":            // 32kbps
            
    $slot "0.18";        // Price for one slot
            
    $min "28";
        break; 
    http://yuxxi.com/calc.php
    Last edited by reyna12; 12-21-2006 at 05:25 PM.

  • #5
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    I'm having trouble understanding
    Quote Originally Posted by reyna12
    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
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #6
    New Coder
    Join Date
    Jan 2006
    Posts
    88
    Thanks
    4
    Thanked 1 Time in 1 Post
    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

  • #7
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Try this:
    PHP Code:
    <?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($minSlotsceil($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
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

  • #8
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Maybe like this.. (Changes in red)
    PHP Code:
    <?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)
    {
    [
    COLOR="Red"]$difference = ($minp $total);
    $slots_to_add = ($difference/$slot);
    $slots $slots $sots_to_add;[/COLOR]
    }
    }
    ?>
    <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
    Last edited by whizard; 12-21-2006 at 06:01 PM. Reason: update in all red
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #9
    New Coder
    Join Date
    Jan 2006
    Posts
    88
    Thanks
    4
    Thanked 1 Time in 1 Post
    Much Much Much Appreciated dumpfi, it works but unfortunately i have no idea how, guess i will have to learn arrays


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •