[thelist] [php] holding objects in classes; problems

James evolt at doubtlesshouse.org.uk
Sun Aug 10 04:12:06 CDT 2003


Apparently it helps to remove the reference passing from these two 
lines,

> $this->dbresults &= $dbr1;
> $dbr1 &= $this->dbresults;

which is exactly the opposite of what you would expect. Strange 
Language.

James.


On Saturday, August 9, 2003, at 12:58 PM, James wrote:

>
> 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>");
>
>
>
>
> ?>
>
> -- 
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester and 
> archives of thelist go to: http://lists.evolt.org Workers of the Web, 
> evolt !



More information about the thelist mailing list