PHP按顺序分隔多个while循环

this is my first post here. I spent all of yesterday searching the net for an answer, but I think I've got a fairly unusual application of the while loop here so I didn't have much success.

Essentially I have a several categories, for example titled "Kosove" and "Shqiperi". Each of these has a number of sub-sections. Those sub-sections may or may not have content inside them. I'm using while loops to display the sub-sections, providing they DO have content inside.

This is my code:

 <ul>
       <?php while(osc_has_list_regions($country = 'kv') ) { ?>

       <li><a href="<?php echo osc_list_region_url(); ?>"><?php echo osc_list_region_name(); ?></a> <em>(<?php echo osc_list_region_items(); ?>)</em></li>
                    <?php } ?>
 </ul>

Notice the " $country = 'kv' " identifies the category as 'Kosove' in this case. What is generated is:

  • Prishtine(1)
  • Vushtrri(1)

Which is fine.

The problem occurs when I want to also display the subsections for another category, e.g. Shqiperi. The code for this:

<ul>
      <?php while(osc_has_list_regions($country = 'kv') ) { ?>

       <li><a href="<?php echo osc_list_region_url(); ?>"><?php echo osc_list_region_name(); ?></a> <em>(<?php echo osc_list_region_items(); ?>)</em></li>
                    <?php } ?>
</ul>

    <br><br>

<ul>
          <?php while(osc_has_list_regions($country = 'al') ) { ?>

          <li><a href="<?php echo osc_list_region_url(); ?>"><?php echo osc_list_region_name(); ?></a> <em>(<?php echo osc_list_region_items(); ?>)</em></li>
                    <?php } ?>
    </ul>

Again notice the " $country = 'al' " identifies the category as 'Shqiperi' in this case. What is generated is:

  • Prishtine(1)
  • Vushtrri(1)

  • Prishtine(1)

  • Vushtrri(1)

Which is not correct. The second part of the code has ignored the 'al' and just repeated the previous while loop content (i.e. the subsections for 'kv').

It SHOULD read:

  • Prishtine(1)
  • Vushtrri(1)

  • Berat(1)

As 'Berat' is the appropriate subsection for the 'Shqiperi' category.

If I have " $country = 'al' " as the first while loop condition, then it shows:

  • Berat(1)

  • Berat(1)

So obviously the order is important. It seems that the previous loop hasn't been properly closed.

I'm pretty new to PHP and I'm not even sure if I'm using the while loop appropriately here. Any suggestions how to fix this would be hugely appreciated.