I'm sure this is stupidly simple, but I havent been able to figure it out with lots of Google searching and pouring through tutorials. I'm building a simple computer trade-in value calculator PHP app. Using a form to select the type of computer and the various specs, I need it to connect to the database that contains the modifier values for each selected component. Then all the modifier values are multiplied against the max value to calculate the trade-in value. Desirable brands and features have higher modifier values, eg. HP = 0.95 vs Acer = 0.7 or Core i7 = 1 vs Celeron = 0.6.
Example:
Product Type: Laptop ($400 - Max Trade-In Value)
Condition: Good (0.95)
Brand: HP (0.95)
OS: Win 7 Pro (1.0)
Processor: Core2Duo (0.9)
Speed: 2.5Ghz (0.95)
Memory: 2GB (0.8)
Trade In Value = ($400 * 0.95 * 0.95 * 1 * 0.9 * 0.95 * 0.8 * ...) = $246.90
The table structures are like this:
brand number value
Acer 1 0.7
Asus 2 1.0
Dell 3 0.95
HP 4 0.95
The number column is the value chosen in one of the drop downs on the form.
So this is what I have so far..
<?php
// Database Connection Info
$username ="xxxxxxxxxxxxx";
$password ="xxxxxxxxxxxxx";
$database ="xxxxxxxxxxxxx";
$con =mysql_connect(localhost,$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($database, $con);
// Recieve $_POST Data from Form
$product_type = $_POST ['product_type'];
$condition = $_POST ['condition'];
$product_brand = $_POST ['product_brand'];
$serial_number = $_POST ['serial_number'];
$operating_system = $_POST ['operating_system'];
$processor = $_POST ['processor'];
$processor_speed = $_POST ['processor_speed'];
$memory = $_POST ['memory'];
$screen_size = $_POST ['screen_size'];
$graphics_card = $_POST ['graphics_card'];
$hard_drive = $_POST ['hard_drive'];
$optical_drive = $_POST ['optical_drive'];
$wireless = $_POST ['wireless'];
$keyboard_mouse = $_POST ['keyboard_mouse'];
$battery = $_POST ['battery'];
$ac_power = $_POST ['ac_power'];
// SELECT Modifier Values from Database ($xxx_v = Modifier Variable)
$product_type_v = mysql_query ("SELECT value FROM product_type WHERE number='$product_type'");
$condition_v = mysql_query ("SELECT value FROM condition WHERE number='$condition'");
$product_brand_v = mysql_query ("SELECT value FROM product_brand WHERE number='$product_brand'");
$operating_system_v = mysql_query ("SELECT value FROM operating_system WHERE number='$operating_system'");
$processor_v = mysql_query ("SELECT value FROM processor WHERE number='$processor'");
$processor_speed_v = mysql_query ("SELECT value FROM processor_speed WHERE number='$processor_speed'");
$memory_v = mysql_query ("SELECT value FROM memory WHERE number='$memory'");
$screen_size_v = mysql_query ("SELECT value FROM screen_size WHERE number='$screen_size'");
$graphics_card_v = mysql_query ("SELECT value FROM graphics_card WHERE number='$graphics_card'");
$hard_drive_v = mysql_query ("SELECT value FROM hard_drive WHERE number='$hard_drive'");
$optical_drive_v = mysql_query ("SELECT value FROM optical_drive WHERE number='$optical_drive'");
$wireless_v = mysql_query ("SELECT value FROM wireless WHERE number='$wireless'");
$keyboard_mouse_v = mysql_query ("SELECT value FROM keyboard_mouse WHERE number='$keyboard_mouse'");
$battery_v = mysql_query ("SELECT value FROM battery WHERE number='$battery'");
$ac_power_v = mysql_query ("SELECT value FROM ac_power WHERE number='$ac_power'");
// Trade In Value Calculation (This is where I'm not sure what to do...)
$value = ( $product_type_v * $condition_v * $product_brand_v * $operating_system_v * $processor_v * $processor_speed_v * $memory_v * $screen_size_v * $graphics_card_v * $hard_drive_v * $optical_drive_v * $wireless_v * $keyboard_mouse_v * $battery_v * $ac_power_v );
//Display Result
// Close Connection
mysql_close($con);
?>
One thing I also need to incorporate is an IF statement that checks the $serial_number value because we can only accept systems with visible serial numbers. If Yes then the calculation is performed, and if No an message is displayed.
Using the mysql_fetch_array I am able to retrieve individual values, but I don't know if I have to use that function for each component...
If someone could give me a suggestion on where to look for material related to this, or some search terms to try that would be greatly appreciated.