dream6120 2018-07-17 13:32
浏览 39
已采纳

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

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>
  • 写回答

1条回答 默认 最新

  • drgweamoi473182981 2018-07-17 13:38
    关注

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据