$this->get_parent($row->category_id);
is calling get_parent with the same ID you originally called it with so it keep recursing until you get a stack overflow.
FYI Depending on your database, it should be possible to do what you want in pure SQL without multiple queries.
Edit: Also, you probably want to do
$ci->db->query("SELECT category ... WHERE category_id=?", array($cat));
instead of what you have now because your current query is susceptable to SQL injection if your function is called with anything other than a number.