2 dropdown
….
<script src="prototype.js" type="text/javascript"></script>
<script src="myAjax.js" type="text/javascript"></script>
</head>
<body>
<form>
<select id="fig" onchange="calc_price();return false;">
<option value = "" selected="selected">Nombre de figures sur la peinture</option>
<option value = "1">1</option>
<option value = "2">2</option>
<option value = "3">3</option>
…
<option value = "10">10</option>
</select>
<select id="dim" onchange="calc_price();return false;">
<option value = "" selected="selected">Dimensions choisies</option>
<option value = "field1">12inx16in/30cmx40cm</option>
<option value = "field2">16inx20in/40cmx50cm</option>
<option value = "field3">20inx24in/50cmx60cm</option>
<option value = "field4">24inx36in/60 cmx90cm</option>
<option value = "field5">30inx40 in/75cmx100 cm</option>
</select>
</form>
<div id="price"></div>
<form>
<input type="submit" value="Submit" onClick="new Ajax.Updater('price','newdbfunction.php',{method: 'post'})";></input>
</form>
</body>
</html>
Newdbfunction.php
<?php
<script>
//Connect to mysql server
$link = mysql_connect("localhost","xxxx","yyyyy"); // ("hostname","username","password");
if(!$link)
die('Failed to connect to server: ' . mysql_error());
//Select database
$db = @mysql_select_db("dddddd"); // dbname
if(!$db)
die("Unable to select database");
$fieldname = $_POST['dim'];
$num = $_POST['fig'];
$qresult = mysql_query("SELECT {$fieldname} FROM price WHERE fig='{$num}'");
$ret = mysql_query ($query) or die(mysql_error());
if(mysql_num_rows($result) > 0){
$data = mysql_fetch_array($result);
if($data[$fieldname] == "-"){
echo "Non-available";
}else{
echo "$" . $data[$fieldname];
}
}else{
echo "Non available";
}
</script>
?>
Javascript file (e.g. myajax.js)
function calc_price(){
if($F('dim') != "" || $F('fig')){
$('price').innerHTML = 'prix not available'; // 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}); } }
Price table name - Price.sql
Prices vs fig and size are non linear variable value
DROP TABLE IF EXISTS `price`;
CREATE TABLE IF NOT EXISTS `price` (
`id` int(3) NOT NULL default '0',
`fig_id` int(3) NOT NULL default '0',
`dim_id` int(3) NOT NULL default '0',
`dim` varchar(20) NOT NULL default '0',
`fig` int(3) NOT NULL default '0',
`price` decimal(10,2) default '0.00',
PRIMARY KEY (`id`),
KEY `price_idx`(`fig`,`dim`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Dumping data for table `price`
--
INSERT INTO `price` (`id`, `fig_id`, `dim_id`, `dim`, `fig`, `price`) VALUES (0, 0, 0, '12x16in/30x40cm', 1, 400.00),
(1, 1, 1, '12x16in/30x40cm', 2, 560.00),
(2, 2, 2, '12x16in/30x40cm', 3, 640.00),
(3, 3, 3, '16x20in/40x50cm', 1, 475.00),
(4, 4, 4, '16x20in/40x50cm', 2, 665.00),
(5, 5, 5, '16x20in/40x50cm', 3, 800.00),
(6, 6, 6, '16x20in/40x50cm', 4, 925.00),
(7, 7, 7, '16x20in/40x50cm', 5, 975.00),
(8, 8, 8, '20x24in/50x60cm', 1, 575.00),
(9, 9, 9, '20x24in/50x60cm', 2, 800.00),
(10, 10, 10, '20x24in/50x60cm', 3, 925.00),
(11, 11, 11, '20x24in/50x60cm', 4, 1050.00),
(12, 12, 12, '20x24in/50x60cm', 5, 1125.00),
(13, 13, 13, '20x24in/50x60cm', 6, 1175.00),
(14, 14, 14, '20x24in/50x60cm', 7, 1250.00),
(15, 15, 15, '24x36in/50x60cm', 1, 700.00),
(16, 16, 16, '24x36in/50x60cm', 2, 900.00),
(17, 17, 17, '24x36in/50x60cm', 3, 1100.00),
(18, 18, 18, '24x36in/50x60cm', 4, 1275.00),
(19, 19, 19, '24x36in/50x60cm', 5, 1350.00),
(20, 20, 20, '24x36in/50x60cm', 6, 1425.00),
(21, 21, 21, '24x36in/50x60cm', 7, 575.00),
(22, 22, 22, '24x36in/50x60cm', 8, 1650.00),
(23, 23, 23, '24x36in/50x60cm', 9, 1750.00),
(24, 24, 24, '30x40in/75x100cm', 1, 775.00),
(25, 25, 25, '30x40in/75x100cm', 2, 1100.00),
(26, 26, 26, '30x40in/75x100cm', 3, 1300.00),
(27, 27, 27, '30x40in/75x100cm', 4, 1475.00),
(28, 28, 28, '30x40in/75x100cm', 5, 1550.00),
(29, 29, 29, '30x40in/75x100cm', 6, 1675.00),
(30, 30, 30, '30x40in/75x100cm', 7, 1800.00),
(31, 31, 31, '30x40in/75x100cm', 8, 1925.00),
(32, 32, 32, '30x40in/75x100cm', 9, 2050.00),
(33, 33, 33, '30x40in/75x100cm', 10, 2200.00);
Bookmarks