PHP Classes

USDA PHP Nutritional Products Database Wrapper: Retrieve nutritional data from USDA database

Recommend this page to a friend!
  Info   View files Example   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 247 This week: 1All time: 7,958 This week: 560Up
Version License PHP version Categories
ndbwrap 0.1GNU General Publi...5PHP 5, Web services, Biology
Description 

Author

This can retrieve nutritional data from USDA database.

It can send HTTP requests to USDA database service API Web server to perform several types of queries about food products and their nutrients.

Currently it can get information about a given nutrient, get information about a given food product, get information about a list of products or nutrients, and search for food products by keywords.

Innovation Award
PHP Programming Innovation award nominee
November 2015
Number 10
The information about the nutrients contained in each type of food can be useful for applications that deal with food.

This class can get the information about nutrients contained in different types of food retrieving them from the USDA Nutritional Products Database.

Manuel Lemos
Picture of Dave Smith
  Performance   Level  
Name: Dave Smith is available for providing paid consulting. Contact Dave Smith .
Classes: 51 packages by
Country: United States United States
Age: 58
All time rank: 618 in United States United States
Week rank: 20 Up3 in United States United States Up
Innovation award
Innovation award
Nominee: 32x

Winner: 7x

Example

<?php
/*
request and display food information
USDA Nutritional Database Wrapper ver 0.1
*/
include('ndbwrap.class.php');

$ndb = new ndbwrap();

$ndbNumber = '01009'; //Cheese, cheddar

$food = $ndb->getFood($ndbNumber);

echo
'<h4>NDB Food Data for ['.$food->report->food->ndbno.'] '.$food->report->food->name.'</h4>';

echo
'<h5>Nutrients per 100 gram portion</h5>';

foreach(
$food->report->food->nutrients as $nutrient ){
   
    echo
'['.$nutrient->nutrient_id.'] '.$nutrient->name.': '.$nutrient->value.$nutrient->unit.'<br>';
   
}

echo
'<hr>';

echo
'database version '.$food->report->sr.'<br>';

echo
$ndb->USDAcitation.'<br>';
?>


Details

Class: ndbwrap Version: 0.1 beta 10/1/2015 Copyright 2015 Wagon Trader, All Rights Reserved Description: This class will retrieve nutritional information for food from the USDA Nutritional Database. Files: ndbwrap.class.php - Main class example.food.php - example to request and display food information example.list.php - example to request and display data lists example.nutrient.php - example to request and display specific nutritional information for foods example.search.php - example to search and display foods that match keywords query Installation: Upload files to a web accessible location on your server (eg. public_html) Configuration: For testing, you can use the supplied API key 'DEMO_KEY'. If you are going to use this class in production you will need to get you own API key available at http://ndb.nal.usda.gov/ndb/api/doc (select sign up now in Gaining Access section) You can change the following settings in the class to meet your specific needs... $datagovKey - Your data.gov API key. $ndbFormat - format of request results. Currently only JSON is supported so you should not change this value $USDAcitation - Recommended citation from the USDA. The USDA data is in the public domain, so there are no restrictions for using it, however this citation is the official text for the source. $dbDomain - URL to REST API. You should only need to change this if the USDA changes their API location. Usage: Refer to example files for usage examples. Refer to ndbwrap.class.php file for instructions on using methods Changelog 0.1 beta release

  Files folder image Files  
File Role Description
Accessible without login Plain text file example.food.php Example Example Usage
Accessible without login Plain text file example.list.php Example Example Usage
Accessible without login Plain text file example.nutrient.php Example Example Usage
Accessible without login Plain text file example.search.php Example Example Usage
Accessible without login Plain text file license.txt Lic. License
Accessible without login Plain text file manual.txt Doc. Documentation
Plain text file ndbwrap.class.php Class Main Class

 Version Control Unique User Downloads Download Rankings  
 0%
Total:247
This week:1
All time:7,958
This week:560Up