I see now. Due to the non-linear multiplication of figs X size, you can't use a simple calculator.
Your first dropdown (fig) will be a number (1 - 10)
Your second dropdown options should have a value equal to the field name of the option displayed.
I'm afraid, I'd use an Ajax solution for this so that users can see the cost before the submit/add to basket button was pressed:
<select id="fig" onchange="calc_price();return false;">
<option value = "" selected="selected">Select a fig</option>
<option value = "1">1</option>
<option value = "2">2</option>
(etc)
</select>
<select id="dim" onchange="calc_price();return false;">
<option value = "" selected="selected">Select a dim</option>
<option value = "field1">12”x16”/30x40 cm</option>
<option value = "field2">16”x20”/40x50 cm</option>
(etc)
</select>
<div id="price"></div>
In a javascript file (e.g. myAjax.js):
function calc_price(){
if($F('dim') != "" || $F('fig')){
$('price').innerHTML = 'Not available';
} else{
var fig = $F('fig');
var dim = $F('dim');
var pars = "fig=" + fig + "&dim=" + dim;
var oAjax = new Ajax.Updater('price','newdbfunction.php',{method: 'post',parameters: pars});
}
}
CREATE a newdbfunction.php file and insert into it:
(create a DBconnection string)
$fieldname = $_POST['dim'];
$num = $_POST['fig'];
$result = mysql_query("SELECT {$fieldname} FROM pricetablename WHERE fig='{$num}'");
if(mysql_num_rows($result) > 0){
$data = mysql_fetch_array($result);
if($data[$fieldname] == "-"){
echo "Not available";
}else{
echo "$" . $data[$fieldname];
}
}else{
echo "Not available";
}
In order to get this to work, you'll need the prototype.js file from
www.prototypejs.org.
Include the javascript files thus:
<script src="/path/to/prototype.js" type="text/javascript"></script>
<script src="/path/to/myAjax.js" type="text/javascript"></script>