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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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