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, CONCAT(foodDescs.long_desc, foodDescs.comname) AS foodDesc, weights.* FROM foodDescs LEFT JOIN weights ON foodDescs.ndb_no = weights.ndb_no WHERE foodDescs.ndb_no = '%s' AND weights.usda_status = 'active' ", $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. multipying by 1 is just an easy way to remove them. $db->_rows[$idx]['amount'] = $db->_rows[$idx]['amount'] * 1; # 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"); ?>