Is the $FarmD variable local in scope? It does not seem to work inside a php function. I thought it might be global.