Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
am I wrong or the function call osc_list_region_url() will always return the same thing? What's inside those functions? –  TGO Jun 16 '13 at 13:00
    
The following links might be useful: doc.osclass.org/… and doc.osclass.org/HLocation.php –  d-sizzle302 Jun 16 '13 at 13:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.