How To Get Next And Before Id With Condition

I have read this:

But i still can’t find any solution, my condition is:

  • i have 2 table, with data like this:

"tbl_film"

id        | 1      | 2

name_film | heroes | smallvile


"tbl_episode"

id      | 1               | 2            | 3

id_film | 1               | 2            | 1

episode | 1               | 1            | 2

preview | This episode... | War begin... | Everyone die, what...

  • To get next and before id with "no condition", i use this function:

$nowPost = $model->id;

$beforePost = $nowPost-1;

$nextPost = $nowPost+1;

$this->menu=array(

	array('label'=>'All Episode', 'url'=>array('index')),

	array('label'=>'Previous Episode', 'url'=>array('view', 'id'=>$beforePost)),

	array('label'=>'Next Episode', 'url'=>array('view', 'id'=>$nextPost)),

);

But my question is how to know the id with condition??

For example, now i am at "tbl_episode" id=1, so how to get the id of next episode "where id_film=1"??

Thank you…