retrieving data from database

i have an array foodtype of food, i want to get the corresponding calorie of each type of food in the array
i’m trying this and i get nothing

i tried to echo something just to test if its entering the IF statement … which i realized its not entering!!
thats the code for the button of ‘Calculate Calories’

<input name="Calculate Calories" type="submit" id="Calculate Calories"  value="Calculate Calories">

[code]else if (isset($_POST[‘Calculate Calories’]))
{
echo ‘Calories’;
// Create connection
$con=mysqli_connect(“localhost”,“root”,"",“inshapewebsite”);
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
foreach ($_SESSION[‘foodTypes’] as $food)
{

$query = “SELECT Calories FROM food where Food=$food”;
$result = mysqli_query($con,$query);
while($row = mysqli_fetch_array($result))
{
echo $row[‘Calories’];
$calories=$calories + $row[‘Calories’];
}
}
echo 'The amount of Calories is: ’ . $calories;
}
[/code]

Maybe something like this?
[php]$query = “SELECT Calories FROM food WHERE Food=$food”;
if ($result = mysqli_query($con, $query)) {

/* fetch associative array */
while ($row = mysqli_fetch_assoc($result)) {
    $calories += $row['Calories'];
}

/* free result set */
mysqli_free_result($result);

}
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service