Loop with a while
- by ookla
Very basic question.. but I'm missing the point.. I have this data on my table:
ID SITEID SECTION
1 1 posts
2 2 posts
3 1 aboutme
4 1 contact
5 2 questions
The output is an array. I can't change it.
I want to make this output on php with a single for loop with that array:
<h1> sections for site 1 </h1>
posts
aboutme
contact
<h1>sections for site 2 </h1>
posts
questions
I'm trying to do something like this, where $sectionsArray is my output. And I want to check if siteid is the same, then make a loop..
for ($j=0;$j<sizeof($sectionsArray);$j++) {
while (siteid==1){
echo "<h1>'.$sectionsArray['siteid'].'</h1>';
}
echo "<A href='section.php?id='.$sectionsArray['id'].' '">'.$sectionsArray['section'].'</a>;
}
But I don't get the logic of "grouping" the results with a while.. INSIDE a loop. Any light will be welcome.
Thanks