I tried to return an object representing the log obtained based on its identifier in the model.
public function getJournal($id) { $query = $this->db->query("SELECT * FROM journals WHERE id='$id'"); return ($query->num_rows() == 1) ? ($query->result())[0] : NULL; }
However, PHP throws an error declaring an unexpected open right bracket ([).
I ended up actually scrolling through an array of 1 object object to return it, which is stupid but works.
public function getJournal($id) { $query = $this->db->query("SELECT * FROM journals WHERE id='$id'"); if ($query->num_rows() == 1) { foreach ($query->result() as $journal) return $journal; } else return NULL; }
What is a shorter way to return this object?
source share