我正在使用 PHP 和 MySQL 数据库管理进行练习,并且正在尝试使用 PHP 从表中的字段返回金额。我试图从foodsID 等于用户选择的foodsID 的foods 表中的CalsPerServ 中获取值。我现在得到的只是一个数组,当我应该返回一个结果时。知道出了什么问题吗?
if($tableName == "meals"){
$foodsID = filter_input(INPUT_POST, "foodsID");
$servings = filter_input(INPUT_POST, "Servings");
$foodsID = mysql_real_escape_string($foodsID);
$servings = mysql_real_escape_string($servings);
$query = "SELECT CalsPerServ FROM foods WHERE foodsID=$foodsID";
$result = mysql_query($query, $connect);
$CalsPerServ = mysql_fetch_assoc($result);
print $CalsPerServ;
$calories = ($CalsPerServ * $servings) * 100;
$sql .= "(foodsID, Servings, Calories) VALUES ('$foodsID', '$servings', '$calories')";
$sqltwo = "INSERT INTO daily_diary (foodsID, CaloriesPlus) VALUES ('$foodsID', '$calories')";
$resulttwo = mysql_query($sqltwo, $connect);
}