Loop with a while

Posted by ookla on Stack Overflow See other posts from Stack Overflow or by ookla
Published on 2010-04-20T22:19:48Z Indexed on 2010/04/20 22:23 UTC
Read the original article Hit count: 390

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about php

Related posts about nested