pagination - How to get choices of each item in a table in cakephp? -
this choices table
id | question_id | content 1 1 bee 2 1 fly 3 1 dog 4 2 cat 5 2 bat 6 2 wasp
and questions table
id | content 1 question1 2 item2
this did.with display question choices..what want now, paginate it,more 1 question per page.how this?your appreciated.thanks
$options['fields'] = array('questions.id','questions.content'); $options['joins'] = array( array( 'table' => 'generated_exam_items', 'alias' => 'genexamitems', 'type' => 'inner', 'conditions' => array( 'genexamitems.generated_examination_id' => 25 ) ), array( 'table' => 'questions', 'alias' => 'questions', 'type' => 'inner', 'conditions' => array( 'questions.id = genexamitems.questions_id' ) ), ); $options['conditions']=array('genexamitems.generated_examination_id' => 25,'question.id=genexamitems.questions_id'); $question_detail = $this->question->find('all',$options); $this->set('questions',$question_detail);
someone please me.!!i dont how , im stuck in almos week..
you can using relation ship each other model
as here adding skeleton code need verify actual code real classname
in question
model write relation
class question extends appmodel { public $hasmany = array( 'choice' => array( 'classname' => 'choice', ) );
and in choice
model can define
class choice extends appmodel { public $belongsto = 'question'; }
and in controller if want fetch speacific question choices can write query below
$question_detail = $this->question->find('first', array( 'conditions' => array('question.id' => $question_id) ));
let me know if can more
Comments
Post a Comment