diff --git a/api/antibiotic.php b/api/antibiotic.php index 013b9c1..260ca6f 100644 --- a/api/antibiotic.php +++ b/api/antibiotic.php @@ -1,3 +1,37 @@ prepare( "SELECT * from antibiotic WHERE id = :id " ); // return all fields (*) from the table WHERE the id is the var $id passed to the function + $query->bindParam( ':id', $id ); + $query->execute(); // Run the SQL query on our database + $query->setFetchMode( PDO::FETCH_OBJ ); // A PHP method to tell the database we want to return all the data as objects with each table represented as a property of that object. This will be the case for most of our calls that return information from the database. http://php.net/manual/en/pdo.constants.php + $data = $query->fetchAll(); + + $data = $data[0]; + + // Build our local object + $this->id = $data->id; + $this->name = $data->name; + $this->notes = $data->notes; + } + } + + + public function get () { + $res['id'] = $this->id; + $res['name'] = $this->name; + $res['notes'] = $this->notes; + + return $res; + } + +} \ No newline at end of file diff --git a/api/diagnosis.php b/api/diagnosis.php index caf106f..36a52b5 100644 --- a/api/diagnosis.php +++ b/api/diagnosis.php @@ -1,5 +1,6 @@ prepare( "SELECT * from diagnosis_antibiotic WHERE diagnosis_id = :id " ); // return all fields (*) from the table WHERE the id is the var $id of current diagnosis + $query = $db->prepare( "SELECT antibiotic_id from diagnosis_antibiotic WHERE diagnosis_id = :id " ); // return all fields (*) from the table WHERE the id is the var $id of current diagnosis $query->bindParam( ':id', $this->id ); $query->execute(); // Run the SQL query on our database $query->setFetchMode( PDO::FETCH_OBJ ); $data = $query->fetchAll(); - - $this->relatedAntibiotics = $data; + foreach ($data as $row) { + $anti = new Antibiotic($row->antibiotic_id); + $this->relatedAntibiotics[] = $anti->get(); + } } - public function get () { + public function get() { $res['id'] = $this->id; $res['name'] = $this->name; $res['notes'] = $this->notes; $res['relatedAntibiotics'] = $this->relatedAntibiotics; - return $res; } + public function getRelatedAntibiotics() { + return $this->relatedAntibiotics; + } + } \ No newline at end of file