echo "<option name=\"$row[modelo]\" value=\"$row[modelo]\">$row[modelo] - $row[preco] €</option>\n";
Well, to start off with, <option> tags don't have a name attribute. You give the <select> tag the name attribute, and the <option> tags have the various value attributes.
But anyway... You know what $processador and $memoria are right? so... just do a sql select:
SELECT sum(price) FROM produtos WHERE modelo='$processador' or modelo='$memoria';
but what you should be doing is what I said before. Use arrays. In HTML if you give elements the same name they will be passed in an array back to the server:
<input type=hidden name=product[] value=1>
<input type=hidden name=product[] value=2>
<input type=hidden name=product[] value=3>
<input type=hidden name=product[] value=4>
then you just get the values out like normal:
<?
$aProducts = $_POST["product"];
?>
then you have an array of all the productID's passed, and you can do lots of stuff with it like SQL selects and whathaveyou.
It works for all elements:
eg:
<input type=checkbox name=product[] value=1>Cpu
<input type=checkbox name=product[] value=2>RAM
<input type=checkbox name=product[] value=3>Graphics Card
<input type=checkbox name=product[] value=4>Monitor
In this case only the checkboxes that are selected will be posted back to the server. All you have to do is
<?
$aProducts = $_POST["product"];
?>
and all the productsID's of the checkboxes the user selected will be in that array.
You should use this approach for your application too. It will make things alot easier for you. Just apply it to whatever elements you are using for the user to select their computer equipment, and then you will get an array posted back to the server of all the productID's they selected.
Then you can just select their respective prices out of the database, and sum them up, or display them, whatever.
Hope that makes sense anyway.
-Adam 🙂