Sheesh, it has been a very long time (almost a year) since I last needed to use PHP and I'm a little hung over on top of that so I am having quie a bit of trouble getting back into things.

Here's my problem. I need to create an array of objects from a MySQL database. I have the fields: ID, Title, Description, Link in a table named Item. I want to load the array with the objects that are returned from the mysql_fetch_object function, using the SELECT * FROM item; query so that all records are returned.

Now, I understand what I need to do, but have been getting the syntax confused (as I have been developing in three other languages for the last year). Firstly, I am having trouble loading the object array from the fetch_object function, and secondly I am not too sure how to access the data within the objects within the array. I am thinking it would be '$objArray[]->Title', to access the Title field, but could really use some confirmation here.

Thanks in advance for all of your help.

Regards.

Steve.

    OK, I soved the problem and for reference here's what I did:

    In my Database Class, I created a method named dbFetchObject and used the following code:

    while($this->obj = mysql_fetch_object($this->dbResult)) {
    			$this->objArray[] = $this->obj;
    		}
    
    	return $this->objArray;
    

    So I can access the object array from the getItems method in my Item Class:

    $this->query = "SELECT * FROM $cfg->itemTable;";
    
    		$this->itemArray = $this->Database->dbFetchObject($this->query);
    
    		return $this->itemArray;
    

    Regards.

    Steve.

      Write a Reply...