I have the following problem:
public function row2Partner($row){ echo $row->PartnerID; } public function main(){ $query = 'SELECT PartnerID, PartnerName FROM Partner'; $result = mysql_query($query); $this->row2Partner(mysql_fetch_object($result)); }
This gives me the error in row2Partner(): Trying to get property of non-object
But $row is an Object! And if I do echo $row->PartnerID in the main function, it works.
Any ideas?
Thx, Martin
If your result returns more than one row, your object is going to be multi-dimensional. I’m pretty sure you can do something like this if you just want to echo the first one:
If you are looking for only one result, I would also limit my query to just one…
If you want to echo out all your rows (in the case of multiple) results, you can do this:
Hope that helps.
PS Just as a sidenote, I tend to like to use associative arrays when dealing with MySQL results–it just makes more sense to me. In this case, you would just do this instead: