require_once("config.php"); require_once("mysimplecode/dbgui/lib/dbgui.php"); require_once("mysimplecode/managefood/conf/db.php"); if ( vr_str("fastget") ){ header("HTTP/1.0 404 Not Found"); ?>
Sorry but this feature was changed. Lookup nutritional information for food, here.
exit(); } $title = 'FoodGenius : '; if ( $ndb_no = vr_str('ndb_no') ){ # needs to be 0 padded to 5 $ndb_no = sprintf("%05s", $ndb_no); # search for a food. $food_recs = sdb_get_recs($GLOBALS['conf_db'], " SELECT fd.* FROM usdasr22.FOOD_DES fd WHERE fd.NDB_No = '$ndb_no' "); $title .= $food_recs[0]['Long_Desc']; } else { $food_recs = like_search_db_get_recs($sql='', $_REQUEST['key']); if ( empty($GLOBALS['is_nutrient']) ){ $food_recs = remove_dupes($food_recs); } } require_once("mysimplecode/foodgenius/lib/header.php"); require_once("mysimplecode/foodgenius/lib/search_form.php"); if ( count($food_recs) == 1 ){ echo "$first = true; foreach($seq_nums as $seq_rec){ if ( ! $first ) echo ", "; ?> ");'> echo $seq_rec['Amount'] . " " . $seq_rec['Msre_Desc']; ?> $first = false; } ?>
foreach($seq_nums as $seq_rec){ ?>| Nutrient | Value | Daily Recommendation | Potential |
|---|---|---|---|
| Size | echo $nutr_recs[0]['Amount'] . " " . $nutr_recs[0]['Msre_Desc'] . " "; echo $nutr_recs[0]['Gm_Wgt'] . " grams"; ?> | list($total_servings, $min_type) = get_potential_serving($volume_in_cups, $weight_grams, $water_grams, $fiber_grams, $calories); echo "Max $min_type at " . (int)$total_servings . " servings."; #echo "($weight_grams, $volume_1gm_in_cup , $volume_in_cups)"; ?> | |
| echo $nrec['NutrDesc']; ?> | echo $nrec['nutrient_amount'] . ' ' . $nrec['Units']; ?> | if ( !empty($nrec['rda_value']) ) echo round(100 * $nrec['nutrient_amount'] / $nrec['rda_value'], 2) . "%"; ?> | percent_comment($volume_in_cups, $weight_grams, $water_grams, $fiber_grams, $calories, $nrec['nutrient_amount'], $nrec['rda_value']) ?> |
"; #echo $key . "\n"; #var_export($like_strings); #echo ""; # $food_res = array(); foreach($like_strings as $str){ if ( substr($str,-1) != '%' ){ # search for a food. $food_recs = sdb_get_recs($GLOBALS['conf_db'], " SELECT fd.* FROM usdasr22.FOOD_DES fd WHERE fd.Long_Desc = '$str' ORDER BY fd.Long_Desc ASC "); if ( !empty($food_recs) ) $food_res =array_merge($food_res, $food_recs); if (count($food_res) > 0 ) return $food_res; # search for a group $food_recs = sdb_get_recs($GLOBALS['conf_db'], " SELECT fd.* FROM usdasr22.FOOD_DES fd, FD_GROUP g WHERE fd.FdGrp_Cd = g.FdGrp_Cd AND FdGrp_Desc = '$str' ORDER BY fd.Long_Desc ASC "); if ( !empty($food_recs) ) $food_res =array_merge($food_res, $food_recs); if (count($food_res) > 0 ) return $food_res; # search for a vitamin $is_nutrient = sdb_get_rec($GLOBALS['conf_db'], " SELECT * FROM NUTR_DEF WHERE NutrDesc = '$str' LIMIT 1 "); if ( $is_nutrient ){ $food_recs = sdb_get_recs($GLOBALS['conf_db'], " SELECT fd.* FROM usdasr22.NUTR_DEF def JOIN usdasr22.FOOD_DES fd JOIN usdasr22.NUT_DATA nd JOIN usdasr22.WEIGHT w WHERE w.NDB_No = nd.NDB_No AND w.Seq = '1' AND def.Nutr_No = nd.Nutr_No AND def.NutrDesc = '$str' AND fd.NDB_No = nd.NDB_No AND fd.FdGrp_Cd IN ( '1600', '2000', '0200', '0900', '1100', '1200' ) ORDER BY nd.Nutr_Val * w.Gm_Wgt DESC LIMIT 500 "); $GLOBALS['is_nutrient']= true; return $food_recs; } } else { $food_recs = sdb_get_recs($GLOBALS['conf_db'], " SELECT * FROM usdasr22.FOOD_DES WHERE Long_Desc LIKE '$str' ORDER BY Long_Desc ASC LIMIT $num_matches "); if ( !empty($food_recs) && $food_recs[0] !== NULL ) $food_res = array_merge($food_res, $food_recs); $food_res =array_merge($food_res, $food_recs); if (count($food_res) > $num_matches ) return $food_res; } } return $food_res; }/*}}}*/ function like_search_permute($key_words, $delimiter=' '){/*{{{*/ if ( count($key_words) <= 1 ) return $key_words; $permutations = array(); foreach($key_words as $index => $key_word){ $word = $key_words[$index]; unset($key_words[$index]); $new_permutations = like_search_permute($key_words, $delimiter); $key_words[$index] = $word; foreach($new_permutations as $pindex => $permutation){ $new_permutations[$pindex] = $word . $delimiter . $permutation; } $permutations = array_merge($permutations, $new_permutations); } return $permutations; } /*}}}*/ function remove_dupes($food_res){/*{{{*/ # remove dupes. if ( empty($food_res) ) return array(); $cnt = count($food_res); for($k = 0; $k < $cnt; $k++){ for($k2=$k + 1; $k2 < $cnt; $k2++){ if ( empty($food_res[$k2]) || empty($food_rec[$k]) ) continue; if ( $food_res[$k]['NDB_No'] == $food_res[$k2]['NDB_No'] ){ unset($food_res[$k2]); } } } # put the shortest at the front. $shortest_len = 1000; $shortest = 0; foreach($food_res as $k => $data){ if ( empty($food_res[$k]) ) continue; if ( strlen($food_res[$k]['Long_Desc']) < $shortest_len ){ $shortest_len = strlen($food_res[$k]['Long_Desc']); $shortest = $k; } } $foo = $food_res[$shortest]; unset($food_res[$shortest]); array_unshift($food_res, $foo); return $food_res; }/*}}}*/ function percent_comment($volume_cups, $weight_grams, $water_grams, $fiber_grams, $calories, $amount, $rda){ if ( ! $rda ) return; list($total_servings, $min_type) = get_potential_serving($volume_cups, $weight_grams, $water_grams, $fiber_grams, $calories); $total_amount = $total_servings * $amount; $tier = $total_amount / $rda; ?> echo round(100 * $tier); ?>% } function get_potential_serving($volume_cups, $weight_grams, $water_grams, $fiber_grams, $calories){ @ $servings_in_calories = 2000 / $calories; @ $servings_in_water = 6000 / $water_grams; # 6 liters. @ $servings_in_weight = 2500 / ( $weight_grams - $water_grams ); @ $servings_in_fiber = 80 / $fiber_grams; @ $servings_in_cups = 4 * 4 * 4 / $volume_cups; # 5 galons. if ( $fiber_grams == 0 ) $servings_in_fiber = 100000; if ( $water_grams == 0 ) $servings_in_water = 100000; if ( $calories == 0 ) $servings_in_calories = 100000; if ( $volume_cups == 0 ) $servings_in_cups = 100000; $total_servings = min( $servings_in_calories, $servings_in_water, $servings_in_weight, $servings_in_fiber, $servings_in_cups ); switch($total_servings){ case $servings_in_calories: $min_type = "calories"; break; case $servings_in_water: $min_type = "water"; break; case $servings_in_weight: $min_type = "weight"; break; case $servings_in_fiber: $min_type = "fiber"; break; case $servings_in_cups: $min_type = "cups"; break; } return array($total_servings, $min_type); }