Price Generator

Junior Spellweaver
Joined
Jun 5, 2005
Messages
192
Reaction score
1
Hey anyone knows any free codes for somthing like a price generator?

What I want it to do is to allow the users to selcet form lists what they want from the service and a price is generated in an area below the form.

Thanks
Jonz
 
Google

...and you'd have to come up with what it's called. Try "price list", "shopping cart", etc.

Well dot you think i tried google... Its not a shopping cart i want...
I want a form with vairous drop down menues and a "generate button" and when u click it it generates a price in the bottom of the form or something
 
I just wrote it, it's really very plain but hope this is what you looking for.
Code:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>PHP Dropdown menu</title>
</head>

<body>

<?php
function form($item)
{
	if (isset($_POST['submit']))
    {
    	if ($item == 'item1')
        {
        	echo 'selected';
        } elseif ($item == 'item2')
        	{
            	echo 'selected';
            } elseif ($item == 'item3')
            	{
                	echo 'selected';
                } elseif ($item == 'item4')
                	{
                    	echo 'selected';
                    } elseif ($item == 'item5')
                    	{
                        	echo 'selected';
                        }
    }
}

$item = $_POST['item'];
switch ($item)
	{
	case 'item1':
    $message = 'You had choosen <b>item1</b> and the cost price is <b>$1,000</b>';
    break;
    case 'item2':
    $message = 'You had choosen <b>item2</b> and the cost price is <b>$2,000</b>';
    break;
    case 'item3':
    $message = 'You had choosen <b>item3</b> and the cost price is <b>$3,000</b>';
    break;
    case 'item4':
    $message = 'You had choosen <b>item4</b> and the cost price is <b>$4,000</b>';
    break;
    case 'item5':
    $message = 'You had choosen <b>item5</b> and the cost price is <b>$5,000</b>';
    break;
    default:
    $message = 'To see the price of an item, please choose the item in the drop down menu and hit the submit button.';
    break;
    }
?>

<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <select size="1" name="item">
    <option value="item1" <?php form($_POST['item']); ?>>item1</option>
    <option value="item2" <?php form($_POST['item']); ?>>item2</option>
    <option value="item3" <?php form($_POST['item']); ?>>item3</option>
    <option value="item4" <?php form($_POST['item']); ?>>item4</option>
    <option value="item5" <?php form($_POST['item']); ?>>item5</option>
  </select><input type="submit" value="Submit" name="submit">
</form>
<?php echo $message; ?>

</body>

</html>

Regards,
SkY
 
Haha.. Thanks for the comment, actually it's not really neat. If you had the chance to see those 'professional' php coders, theirs will be more neat then mine.

Ok cya, time to work.
 
Damn your php code is neat and tidy lol.
Not really. The first set of ifs could be condensed into one statement with the || (or) operator. The huge unnecessary indents are annoying and confusing.
PHP:
if (($item == 'item1')||($item == 'item2')||($item == 'item3')||($item == 'item4')||($item == 'item5'))
 echo 'selected';

There's also a lot of redundancy in the second portion - use variables and arrays to clean it up a bit. For example, "'You had choosen " and "and the cost price is " is repeated 5 times, this can all be condensed into one statement with the use of variables.
 
HEY MAN THANKS SOO MUCH
I really apprechiate it
Thanks agian for using some of your time to do this
I'm currently installing it

Ok installed it... now one question... Can i have a load of form values like other drop down boxes proberly 4 more and it totals up at the bottom.... exact thing that u have there except it has more options in other drop down menus to chose from? ... I hope it isnt to much troble...

Thanks
Jonz
 
Last edited:
What about using javascript for instant price totals without having to reload a page?
Well i dont know how to code one and i havent found anything on it on google
if u got one that will be good.... but if Hacker can do one well his is really good
 
A better way would be to do it server-side; this way, you can ensure that your solution will work on all browsers and environments. Actually, a database-based (excuse the awkward wording) solution, with a MySQL database storing the list of items and prices, would be a better choice; in addition, MySQL can do the summing of the required columns or rows, which is much faster than doing it via PHP.
 
A better way would be to do it server-side; this way, you can ensure that your solution will work on all browsers and environments. Actually, a database-based (excuse the awkward wording) solution, with a MySQL database storing the list of items and prices, would be a better choice; in addition, MySQL can do the summing of the required columns or rows, which is much faster than doing it via PHP.

Also its alot more secure and you can do alot more with MySQL.
Or if you don't feel like doing MySQL, you could use javascript + ajax.
 
Well its really just to generate an estimate price based on what the user chooses from the lists so i don't need it being secure or anything.
What Hacker has is exacactly what I need except more drop down menus.

I think that it would work like each menu item has a price... then you choose from a list of all the other menu items and then it adds it up and gives the price as shown here:

this is the work Hacker/ Sky did:
PHP Dropdown menu

this is what i want:
Exucutive Car & Limousine - Rate
(it doesn't work but its the idea)
 
Is it possible to make something which adds up all the valuse enterd in the form?
I might be able to code the rest my slef if it is explained

no its not for a school project
 
Not really. The first set of ifs could be condensed into one statement with the || (or) operator. The huge unnecessary indents are annoying and confusing.
PHP:
if (($item == 'item1')||($item == 'item2')||($item == 'item3')||($item == 'item4')||($item == 'item5'))
 echo 'selected';

There's also a lot of redundancy in the second portion - use variables and arrays to clean it up a bit. For example, "'You had choosen " and "and the cost price is " is repeated 5 times, this can all be condensed into one statement with the use of variables.

Thanks for enlighten me :)

this is what i want:
Exucutive Car & Limousine - Rate
(it doesn't work but its the idea)

Can you give me some examples which items selected will give what result, by the way please add in your html where you want the result to be shown.
Hope I had the time to do it tomorrow.
 
Haha.. Thanks for the comment, actually it's not really neat. If you had the chance to see those 'professional' php coders, theirs will be more neat then mine.

Ok cya, time to work.

Funny you should say that..

Cause your entire 58 lines of code can be replaced by these 16:
PHP:
<?php
$items = array("item1" => "$1,00", "item2" => "$2.00");
$post  = $_POST['item'];

$output    = "<form method='POST' action='$_SERVER[PHP_SELF]'>
                <select size='1' name='item'>";
foreach($items as $item => $price) {
  $select  = $post == $item ? "selected" : "";
  $output .= "    <option $select>$item</option>";
}
$output   .= "  </select>
                <input type='submit' value='Submit' name='submit'>
              </form>";
if($post)
  $output .= "You had choosen <b>$post</b> and the cost price is <b>$items[$post]</b>";

echo $output;              
?>

And then I'm not even trying.. :icon6:

To use multiple items and add them up, simply copy-paste the input field and give it a new name, like item_a, item_b, etc. Then the cost price will be something like $items_a[$_POST[item_a]] + $items_b[$_POST[item_b]], etc. Takes a bit of figuring out, but that'll be a nice learning experience :)

By the way, if its a static script that doesn't need changing, use javascript instead of a form with PHP. No need for a reload anymore and easier maintainable and portable code.
 
Last edited:
Ohh damm lol ... thanks alot Sky and Frag I really apprechiate your help... I dont want anyone to waste any mroe time on this... I'll try to do the rest for my slef ... if i cant well lol :P

thanks alot evryone
 
Last edited:
Back