I want to create simple poll system. I have two question and two answers. First Question has two answer but second question hasn’t any answer. In a sense I want to get:
First question?
Answer1
Answer2
Second question?
But I’m getting
First question?
Answer1
Answer2
Second question?
Answer1
Answer2
Second question need not to have Answer1 and Answer2(same with First question answers but I have two answer in mysql).
And my foreach loops.. How need i to change my loops?
foreach($sorular->soruCek($_GET["kategori"]) as $data) // Questions
{
echo $data["soru"] . "<br/>";
foreach($sorular->cevapCek($data["id"]) as $cevaplar) // Answers
{
echo $cevaplar["cevap"] . "<br/>"; // This needn't print data to below of Second Question
}
}
You have to fetch the data inside the inner loop first, make sure it has values before printing the – what I assume is – a header?