I have a drink calculator that pulls from mysql the weight and sex of the person to figure out what their blood alcohol level is based on how many drinks they have had over time. I need to factor in the strength of drinks. Some drinks are stronger than others. Most of the drinks in the database table have a value of one but a few are more and some are less. The table is called DrinkType
. It has a list of the drinks and their corresponding value.
I am trying to figure out how to do a second query to pull the drink type number and then multiply the final result by it. Any help is greatly appreciated.
Update:
Thanks to everyone for their help. I pasted the code supplied by Dainis and I am getting an error about the array. The error is : Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/netmonge/public_html/note/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 22. I think it may be because I don't have the table for DrinkType done correctly. That table has a Drink column with the names of the drink that can be selected from the form, and an Alcohol_Content column which consist of primarily ones. That column needs to be selected based on the drink chosen in the form and multiply the result ( $row2[$Alcohol])...
<?php
require_once( 'db-connect.php' );
if( isset( $_POST['Sex']) ) {
$sex = mysql_real_escape_string( $_POST['Sex'] );
$weight = mysql_real_escape_string( $_POST['Weight'] );
$number = mysql_real_escape_string( $_POST['Number'] );
$hours = mysql_real_escape_string( $_POST['Hours'] ) * 0.015;
$Drinktype = mysql_real_escape_string( $_POST['Drink'] );
$Alcohol = mysql_real_escape_string( $_POST['Alcohol_Content'] );
$query = "SELECT $number
FROM $sex
WHERE body_weight <= '$weight lb'
ORDER BY body_weight DESC";
$result = mysql_query( $query) ;
$row1 = mysql_fetch_array( $result );
$query = "SELECT $Alcohol
FROM $Drinktype";
$result = mysql_query( $query ) or die($query."<br/><br/>".mysql_error());;
$row2 = mysql_fetch_array( $result );
$result = $row1[$number] - $hours * $row2[$Alcohol];
$result = "Your Blood Alcohol Level is: $result%";
}
?>