检查所选记录后是否还有其他记录

Hi I am using the following code to get the next record in the database.

However if it is the last record I get an error.

Any ideas on how i can just skip the below code if the $track->id is the last record?

Thank you

$nxt = $this->db->get_where("academytracks", ["id >" => $track->id]);
$nxt = $nxt->row();
$data['nxttrack'] = $nxt;

THE ERROR I GET

<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
   <h4>A PHP Error was encountered</h4>
   <p>Severity: Notice</p>
   <p>Message: Trying to get property of non-object</p>
   <p>Filename: controllers/academy.php</p>
   <p>Line Number: 126</p>
</div>

I think you will find you have DESTROYED the $nxt variable holding your handle to the resultset.

Try using another variable like this

$nxt = $this->db->get_where("academytracks", ["id >" => $track->id]);
$row = $nxt->row();
$data['nxttrack'] = $row;