Yii框架中有「Undefined offset」錯誤,如果下一個id爲null,並且如果上一個id爲前一個id爲null,那麼我需要先轉到第一個id?Yii上未定義的偏移量錯誤
public static function getNextOrPrevId($currentId, $nextOrPrev)
{
$records=NULL;
if($nextOrPrev == "prev")
$order="id DESC";
if($nextOrPrev == "next")
$order="id ASC";
$records=Photo::model()->findAll(
array('select'=>'id', 'order'=>$order)
);
foreach($records as $i=>$r)
if($r->id == $currentId)
return $records[$i+1]->id ? $records[$i+1]->id : NULL;
return NULL;
}
錯誤行
return $records[$i+1]->id ? $records[$i+1]->id : NULL;
你是什麼意思「如果最後一個ID如果以前的ID爲空?」 ? – 2012-01-16 20:56:44