Here's my problem. I'm using a set of drop down boxes to configure a product for sale. These attributes are stored in a database and PHP is used to create the drop down boxes(code pasted below). Problem I'm have is that I need to show the new price. With PHP I can only do this with a refresh, but when I refresh, the selections made are wiped out. Is there anyway to update a new price, possibly with a combonation javascrip/php? I was thinking possibly a button linked to some javascript which would recalculate the price and print it out. IS that possible at all? Thanks.
<?php
if ($products_attributes == '1') {
$products_options_name = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . $HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . $languages_id . "'");
echo '<b>' . TEXT_PRODUCT_OPTIONS . '</b><br>';
echo '<table border="0" cellpading="0" cellspacing"0">';
while ($products_options_name_values = tep_db_fetch_array($products_options_name)) {
$selected = 0;
$products_options = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . $HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . $products_options_name_values['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . $languages_id . "'");
//heres an attempted change
if ($products_options_name_values['products_options_name'] == "Processor") { print ("Processor goes here");}
//end of attempt
echo '<tr><td class="main">' . $products_options_name_values['products_options_name'] . ': </td><td>' . "\n" . '<select name ="id[' . $products_options_name_values['products_options_id'] . ']">' . "\n";
while ($products_options_values = tep_db_fetch_array($products_options)) {
echo "\n" . '<option name="' . $products_options_name_values['products_options_name'] . '" value="' . $products_options_values['products_options_values_id'] . '"';
if ( ($products_options_values['options_values_price'] == 0 && $selected == 0) || ($cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name_values['products_options_id']] == $products_options_values['products_options_values_id'])) {
$selected = 1;
echo ' SELECTED';
}
echo '>' . $products_options_values['products_options_values_name'];
if ($products_options_values['options_values_price'] != '0') {
echo ' (' . $products_options_values['price_prefix'] . $currencies->format($products_options_values['options_values_price']) .') ';
}
echo '</option>';
};
echo '</select></td></tr>';
}
echo '</table>';
}
?>
updating dynamically
Moderator: General Moderators
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
-
JPlush76
- Forum Regular
- Posts: 819
- Joined: Thu Aug 01, 2002 5:42 pm
- Location: Los Angeles, CA
- Contact:
here is a little script that I use to keep the values of drop boxes if there is an error or the page refreshes...
and here is how you call the function:
Code: Select all
<?php
// FUNCTION FOR CREATING SELECT BOXES AND KEEPING THEIR VALUE FOR DISPLAY
function create_select ( $Sname, $table, $class, $any = "",$av, $cid, $cname, $select_id, $order) {
# $Sname is the name to be applied to the select control.
# $table is the name of the table to query.
# NOTE: This function assumes you are using a lookup table that has 2 fields (id,name) or you only name those 2 fields in your sql statement.
# $any 0=Without the "Any" option, 1=With the "Any" option, this is a NULL value.
# $curr_id is used to set the "SELECTED" flag on the select control.
$result = query_db("SELECT * FROM $table");
$html = ""; //variable holding all the html to be printed
$html.="<select name="$Sname" class="$class">\n";
if ($any != "") {
$html.="<option value="$av">$any\n";
}
while ($row = mysql_fetch_array($result)):
$id = $rowї"$cid"];
$name = $rowї"$cname"];
if ($id == $select_id) {
$html.="<option SELECTED value="$id">$name\n";
} else {
$html.="<option value="$id">$name\n";
}
endwhile;
$html.="</select>\n";
return $html;
}// END FUNCTION
?>and here is how you call the function:
Code: Select all
<?php
echo create_select("f_state","states","boxform","select a state","","states_id","states_desc",$_POSTї'f_state'],"2");
?>