will initialize a global variable for every field in a given table
reduces coding later if a table structure changes
written by Victor M. Font Jr.
Abba Consulting group
http://abba.fontlife.com
this version requires that phplib is installed on your server
*/
function initvar($varname, $value=null){
global $$varname;
if(!isset($$varname)){
if ($value == null){
$$varname = "";
}else{
$$varname = $value;
}
}
}
$db = new DB_Example;
// populate this array with the tables for which you are initializing variables
$sTableList = array("table1","table2","table3","table4","table5");
for ($n=0; $n<=(count($sTableList)-1); $n++){
$results = $db->metadata($sTableList[$n], true);
for ($i=0; $i<$results["num_fields"]; $i++){
/*
if you want to initialize variables for types other
than strings and numbers, you'll have to add your own
type in the switch statment below
*/
switch ($results[$i]["type"]){
case "string":
initvar($results[$i]["name"]);
break;
case "int":
initvar($results[$i]["name"],0);
break;
case "blob":
initvar($results[$i]["name"]);
break;
}
}
}
?>