This is my second post today because I'm very new at OOP in PHP, so bear with me if it's a silly question...
I've created a beautiful class that I want to be able to use with my "JOB" objects that includes being able to use this single object to pull data from many tables so the end user sees relevant data. For instance, in my class, I have:
public function showProjectManager() {
$q = "SELECT m.name FROM " . jJOBS . " AS j JOIN " . jMEI . " AS m ON m.uid = j.mei WHERE id = " . $this->id;
$r = $this->_dblink->query($q);
$row = $r->fetch_assoc();
return $row['name'];
}
because the data stored in the jJOBS table is merely a number that references an id in another table. There are several pieces of data like this stored in the main jJOBS table.
So, in another section of code there is a dropdown box that lets the user select a specific "JOB" and using an AJAX call I want to display the data from that JOB. What I'm trying to do is create a JOB object (which includes the showProjectManager method), read all the properties from a database using mysqli_fetch_object and then call the showProjectManager method, like this:
$disp = new Job();
$q = "SELECT * FROM " . jJOBS . " WHERE id = " . $job_id;
$r = $jobsdb->query($q);
$disp = $r->fetch_object();
$zList .= "<li><span class='smLabels l'>Project Manager :</span>\n<span class='smText r'>" . $disp->showProjectManager() . "</span></li>";
But whenever I fetch the object from the DB, the $disp object reverts back to stdClass. How can I maintain the proper class and access the values I need from the DB? Everything I have read on the subject calls for the use of a DataMapper which seems incredibly complex, especially for this scenario.