PHP Classes
elePHPant
Icontem

File: example.nutrient.php

Recommend this page to a friend!
  Classes of Dave Smith  >  USDA PHP Nutritional Products Database Wrapper  >  example.nutrient.php  >  Download  
File: example.nutrient.php
Role: Example script
Content type: text/plain
Description: Example Usage
Class: USDA PHP Nutritional Products Database Wrapper
Retrieve nutritional data from USDA database
Author: By
Last change:
Date: 4 years ago
Size: 1,021 bytes
 

 

Contents

Class file image Download
<?php
/*
request and display specific nutritional information for foods
USDA Nutritional Database Wrapper ver 0.1
*/
include('ndbwrap.class.php');

$ndb = new ndbwrap();

$ndb->addNutrient('205');
$ndb->addNutrient('204');
$ndb->addNutrient('208');
$ndb->addNutrient('269');

$ndb->addFoodGroup('0100');
$ndb->addFoodGroup('0500');

$nutrients = $ndb->getNutrient(10);

echo
'<h4>NDB Nutrient Data</h4>';

echo
'<h5>Showing '.$nutrients->report->end.' of '.$nutrients->report->total.' items found</h5>';

foreach(
$nutrients->report->foods as $food ){
   
    echo
'<strong>['.$food->ndbno.'] '.$food->name.'</strong><br>';
   
    echo
'Serving Size: '.$food->measure.'<br>';
   
    foreach(
$food->nutrients as $nutrient ){
       
        echo
'['.$nutrient->nutrient_id.'] '.$nutrient->nutrient.' '.$nutrient->value.$nutrient->unit.'<br>';
       
    }
   
}

echo
'<hr>';

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

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