[thelist] [php] holding objects in classes; problems
James
evolt at doubtlesshouse.org.uk
Sat Aug 9 06:58:31 CDT 2003
This code fails on the line marked with a star with a <b>Fatal
error</b>: Call to a member function on a non-object in ....
Why? It has to be some problem with storing the object in the class.
The Pear DB results object is stored in ListField.Init but lost in
ListField.GetNextResult
Thanks for any help,
James.
<?
ini_set("include_path", "/CompiledSoftware/php");
require_once "DB.php";
$DataBase = DB::Connect("mysql://jobtracker:@localhost/jobtracker");
if (DB::isError($DataBase)) {
die ("Could not connect to the DataBase - Error is:
".$DataBase->getMessage());
}
class ListField {
var $dbresults;
var $row;
function Init($field) {
if ($field=="CompanyName") {
$table="Company";
$this->row="Name";
} elseif ($field=="JobTitle") {
$table="Job";
$this->row="Title";
} elseif ($field=="JobLocation") {
$table="Job";
$this->row="Location";
}
$sql = "SELECT " . $this->row ." FROM $table GROUP BY " . $this->row;
$dbr1 = $GLOBALS["DataBase"]->query($sql);
if (DB::isError($dbr1)) {
die("DataBase Error listing fields: ".DB::errorMessage($dbr1));
}
$this->dbresults &= $dbr1;
}
function GetNextResult() {
$dbr1 &= $this->dbresults;
if ($line = $dbr1->fetchRow(DB_FETCHMODE_ASSOC)) {
*******************
return $line[$this->row];
} else {
return FALSE;
}
}
}
$results = new ListField();
$results->Init("CompanyName");
echo("<select size=10 name=CompanyName >");
while ($line = $results->GetNextResult()) {
echo("<option>" .$line ."</option>");
}
echo("</select><P>");
?>
More information about the thelist
mailing list