I have 3 tables "Questions", "Answers", & "Results". I want to fetch multiple rows from 3 tables, one by one and display it sequentialy.
PROGRAM
$questions = Questions::find_by_qpno($qpno);
$answers = Answers::find_by_apno($apno);
$results = Results::find_by_rno($rno);
foreach($questions as $question) {
echo "Question";
echo $question->question;
}
foreach($answers as $answer) {
echo "Answer";
echo $answer->answer;
}
foreach($results as $result) {
echo "Result";
echo $result->remark;
}
OUTPUT
Question
What is software engineering?
Question
What are SDLC models available?
Answer
Software engineering is making softwares
Answer
Waterfall , spiral etc
Remark
It is correct Software engineering is making softwares.
Remark
good Waterfall , spiral etc correct
WANT
Question 1
Answer 1
Remark 1
Question 2
Answer 2
Remark 2
Need a Simple way to nest 3 foreach loops so that I get it in the order Question - Answer - Remark ?
note: I know I could count objects from the SQL query. put $count = count($questions)
. and use a for loop for($i=1 ; i<=$count ; $i++)
and iterate through these three sequentialy. but it looks ugly.
What is the best way to do this ?