From d895b852a6e160496ffc760d46d3719a3d62ff86 Mon Sep 17 00:00:00 2001 From: Nathan Kinkade Date: Sun, 3 Feb 2008 23:23:24 +0000 Subject: Initial checkin of nutridb.org and basic subversion directory structure --- food_quantity.php | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 food_quantity.php (limited to 'food_quantity.php') diff --git a/food_quantity.php b/food_quantity.php new file mode 100644 index 0000000..d86c6b3 --- /dev/null +++ b/food_quantity.php @@ -0,0 +1,70 @@ +assign("food", $food); +} else { + $_SESSION['systemMsg'] = "You must specify a food."; + header("Location: {$config->_rootUri}/"); + exit; +} + +# get the selected food and quantities from the database +$sql = sprintf (" + SELECT foodDescs.sciname, %s AS foodDesc, weights.* + FROM foodDescs LEFT JOIN weights + ON foodDescs.ndb_no = weights.ndb_no + WHERE foodDescs.ndb_no = '%s' + ", + $db->_dbConn->Concat("foodDescs.long_desc", "', '", "foodDescs.comname"), + $food +); +$db->Select($sql); +# if for some reason the ndb_no doesn't exist, then drop them where they +# came from with an appropriate error message +if ( $db->_rowCount > 0 ) { + $smarty->assign("foodQuantities", $db->_rows); +} else { + $_SESSION['systemMsg'] = "The food you specified doesn't seem to exist."; + header("Location: {$config->_previousUri}"); + exit; +} + +# increment the counter for this food. this counter could be used for all +# sorts of things, for example it is the basis of the "sort by popularity" option. +# the more people that select this item, the higher in the sort list it +# will appear. +incrementPopularityCounter($food, "foodDescs"); + +# some data housekeeping +for ( $idx = 0; $idx < count($db->_rows); $idx++ ) { + # the data from the USDA frequently has low order, unnecessary zeros to the + # right of the decimal. here we strip off any superfluous zeros and/or + # decimal points + $db->_rows[$idx]['amount'] = trim($db->_rows[$idx]['amount'], ".0"); + + # trim any extra commas from the end of foodDesc, as may appear + # due to the concatenation of long_desc and comname with a comma + # where comname has no value, which it frequently doesnt' + $db->_rows[$idx]['foodDesc'] = trim($db->_rows[$idx]['foodDesc'], ", "); +} + +$smarty->assign("foodQuantities", $db->_rows); + +# grab the various parts. these sections are not printed to the screen +# but rather dumped into smarty variables that will simply be printed +# in the template, so the order doesn't matter here at the moment +require("header.php"); +require("sidebar_left.php"); +require("sidebar_right.php"); +require("footer.php"); + +$smarty->display("food_quantity.tpl"); + +?> -- cgit v1.2.3