Help Creating a Pricing PHP Tool

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
terpsnation
Forum Newbie
Posts: 3
Joined: Sun Jun 08, 2008 9:10 pm

Help Creating a Pricing PHP Tool

Post by terpsnation »

Hi,

I currently run a website for World of Warcraft powerleveling (yay dorks.)

I am setting up a new option for a customer to add to their cart, and it goes a little like this:


I need to have two drop down menu's, one for the initial level, and one for the desired level. Each level has a dollar value:

60-61: $9
61-62: $10
62-63: $11
63-64: $12
64-65: $13
65-66: $14
66-67: $15
67-68: $16
68-69: $17
69-70: $18


So, if a customer selected to be leveled from 60 to 70, the total would be $135.


I have the HTML section of this tool set up, but I have no idea how to create a PHP tool to allow this to happen. Is there anyone out there who could be of any help?


Thank you :)

Terps
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Help Creating a Pricing PHP Tool

Post by onion2k »

Those prices don't make sense. If the numbers are 60 - 60.999 then there's no value for 70. If they're 60.001 - 61 then there's no value for 60. If it's anything else then there's two values for the numbers between 61 and 69.

How much would it be if I only bought 60?
How much would it be if I only bought 65?
How much would it be if I only bought 70?
User avatar
Frozenlight777
Forum Commoner
Posts: 75
Joined: Wed May 28, 2008 12:59 pm

Re: Help Creating a Pricing PHP Tool

Post by Frozenlight777 »

I think it's funny that people actually pay for this.
Those prices don't make sense. If the numbers are 60 - 60.999 then there's no value for 70. If they're 60.001 - 61 then there's no value for 60. If it's anything else then there's two values for the numbers between 61 and 69.
There only supposed to be whole numbers I believe.

Code: Select all

<form action = "submitprices.php" method="POST">
<select> <option name="1" value="1"> 1 </option>
<input type="submit" value="Power Level Me">
</form>

then in the submitprice.php file do
$1 = $_post["1"];
insert to a database and whatever what you want to with it...
terpsnation
Forum Newbie
Posts: 3
Joined: Sun Jun 08, 2008 9:10 pm

Re: Help Creating a Pricing PHP Tool

Post by terpsnation »

Okay, that makes sense Frozen...thanks a bunch.

As for the pricing, this is how it goes:

I just designated a price for each level, so if your account was level 60, and you wanted it to be 61, it would cost 9 dollars. If you wanted it to be 62, it would cost 9 + 10 dollars. So for 60-70 it would cost 9+10+11+12 (all the way up to 18) dollars. There's no inbetween when it comes to levels.

Thanks for your help guys.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Help Creating a Pricing PHP Tool

Post by Jonah Bron »

So, the cost to step up grows as you step up higher? I think the logic here, is that to get to (eg 64), if you are at (eg 60), you have to pay to get to 61, then pay to get to 62, then to 63, then 64.

You need a select dropdown like this:

Code: Select all

<select name="currentLevel">
    <option value="60">60</option>
    ...
    <option value="69">69</option>
</select>
<select name="newLevel">
    <option value="61">61</option>
    ...
    <option value="70">70</option>
</select>
And, code like this:

Code: Select all

<?php
$array = array();
$array[61] = 9;// amount to move from 60 to 61
$array[62] = 10;// amount to move from 61 to 62
$array[63] = 11;// amount to move from 62 to 63
// ...
$array[70] = 18;// amount to move from 69 to 70
 
$start = $_POST['currentLevel'];// get viewer's current level
$end = $_POST['newLevel'];// get viewer's desired level
$total = 0;// create a total variable
for ($i = $start; $i <= $end; $i++){// run through the array of prices from the current level to the desired level
    $total += $array[i];// add that cost to the total
}
// $total is the total amount
?>
Now, please realize that programing in such a static manner is rarely a good idea. This is just a bit of programing logic to put you on the right track. It would be best to store the amounts in an XML file, or a Database.
terpsnation
Forum Newbie
Posts: 3
Joined: Sun Jun 08, 2008 9:10 pm

Re: Help Creating a Pricing PHP Tool

Post by terpsnation »

Okay, that makes everything a lot clearer now PHPYoungster.


But how would I integrate the HTML and the PHP to have it add up the total. I use a tool called ZenCart to run my entire website...any idea how I'd be able to create a price then have ZenCart recognize the cost that has been calculated, or is this impossible.

What I just said is probably a little confusing to everyone other than me...what I mean is, okay, so the PHP calculates the price...but how will ZenCart understand that this number is a price, and not just a number. Would I have to edit the code of ZenCart as well?
Post Reply