Jump to content

Calculating prices and displaying price


MsKazza

Recommended Posts

Hi there,

I'm coding a products page (pls see : http://agraphics.ie/products.php?recordID=4) so far i have it picking up the products from the database, filtering categories via the menu, and then product weight and quantity on the page.  My problem is that i need to display the price at the bottom and also have it add or take away 49€ depending on the radio button.  Any help much appreciated as i'm running out of time.  I tried experts-exchange but so far nothing from them.

 

Thanks in advance for any help.

MsKazza

:)

Link to comment
https://forums.phpfreaks.com/topic/230839-calculating-prices-and-displaying-price/
Share on other sites

could try something like.....

 

<?php
$available_options = array("op1_value"=>"Option 1",
                           "op2_value"=>"Option 2",
                           "op3_value"=>"Option 3",
                           "op4_value"=>"Option 4",
                           "op5_value"=>"Option 5",
                           "op6_value"=>"Option 6",
                          );

$processing_message = '';
if (isset($_POST['option_choice'])) {
  switch ($_POST['option_choice']) {
    case 'op1_value':
      $processing_message = 'Nice choice!';
      break;
    case 'op2_value':
      $processing_message = 'Good choice.';
      break;
    case 'op3_value':
      $processing_message = 'OK choice.';
      break;
    case 'op4_value':
      $processing_message = 'Moderate choice.';
      break;
    case 'op5_value':
      $processing_message = 'Horrible choice.';
      break;
    default:
      $processing_message = 'Incorrect';
      //In this example, either op6_value is chosen, or something else was entered (say through a hack of the form)
      break;
  }
}
if (strlen($processing_message) > 0) {
  echo '<div class="processing_message">'.$processing_message.'</div>';
}
echo '<form method="post" action="'.basename(__file__).'">';
foreach($available_options as $option_value=>$option_label) {
  //Notice the use of the ternary operator ()?: to check the selected radio button after the form was submitted.
  echo $option_label.'<input type="radio" name="option_choice" value="'.$option_value.'" '.(($option_value == $_POST['option_choice'])?' checked="checked"':'').'/><br />';
}
echo '<input type="submit" value="Check Answer" />';
echo '</form>';
?> 

 

then in the option you want to it to subtract from just put $total price minus 45 where $message is supposed to go under the case.

thank you but i don't see how that applies to what i'm asking, i have three drop down boxes on my page, product, weight and quantity.  I want to use the dropdowns to filter the recordset, so choosing a specific product will filter down to only the weight and quantities possible for that product, then when they choose weight and quantity it will display the price for that specific product at the end of the page.

 

Please help urgent.  I have to get this done today, one way or another.

Thanks

MsKazza

if you want to change the price button on select you need to find a javascript function (google) that onclick of the selected text will change the button.

 

this is not a PHP matter.

 

 

somthing like below should work on select it will go to a new page.

 

http://www.codeproject.com/KB/scripting/autoselect.aspx

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.