*

Fantasy

  • **
  • 7 posts
Menu based on the selection of cities or regions
« on: May 08, 2022, 05:41:09 PM »
Hello, community. I'm a beginner in Osclass and PHP. Please I need your help.

I'm trying to create a footer menu based on the selection of cities or regions in descending order of the number of items.

One part of the code displays the selection based on cities, and the other part of the code displays the selection based on regions.

Each of the two parts of the code works if I add them to the page one at a time.

If I add them at the same time, the second code displays white (blank) entries.

Where did I make the mistake? Thank you very much.




<?php $cities = CityStats :: newInstance()->listCities('%%%%', '>', 'i_num_items DESC'); ?>
      <?php $i = 1; ?>
<select name="sCity" id="sCity" onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">   
<option value="">Select a city</option> 
      <?php foreach($cities as $c) { ?>
        <?php if($i <= 30) { ?>
      <option value="<?php echo osc_search_url(array('page' => 'search', 'sCity' => $c['city_id']));?>"><?php echo $c['city_name'];?> (<?php echo $c['items']; ?>) </option>
          <?php $i++; ?>
        <?php } ?>
      <?php } ?>       
</select>
   
<?php $regions = RegionStats :: newInstance()->listRegions('%%%%', '>', 'i_num_items DESC'); ?>
      <?php $i = 1; ?>
<select name="sRegion" id="sRegion" onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">   
<option value="">Select a region</option> 
      <?php foreach($regions as $r) { ?>
        <?php if($i <= 30) { ?>
      <option value="<?php echo osc_search_url(array('page' => 'search', 'sRegion' => $r['pk_i_id']));?>"><?php echo $r['s_name']; ?> (<?php echo $r['i_num_items']; ?>)</option>
          <?php $i++; ?>
        <?php } ?>
      <?php } ?>       
</select>

*

MB Themes

Re: Menu based on the selection of cities or regions
« Reply #1 on: May 09, 2022, 07:19:36 AM »
Try to use same naming convention in regions as you did in cities.
s_name ==> region_name
pk_i_id ==> city_id
i_num_items ==> items
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

Marked as best answer by frosticek on May 09, 2022, 03:11:30 PM
*

Fantasy

  • **
  • 7 posts
Re: Menu based on the selection of cities or regions
« Reply #2 on: May 09, 2022, 02:27:31 PM »
Thank you very much, MB Themes!  :D Now it works properly.

Below is the fully functional code, maybe other forum members need it too:
Code: [Select]
<?php $cities CityStats :: newInstance()->listCities('%%%%''>''i_num_items DESC'); ?>
      <?php $i 1?>
<select name="sCity" id="sCity" onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
<option value="">Select a city</option> 
      <?php foreach($cities as $c) { ?>
        <?php if($i <= 30) { ?>
<option value="<?php echo osc_search_url(array('page' => 'search''sCity' => $c['city_id']));?>"><?php echo $c['city_name'];?> (<?php echo $c['items']; ?>) </option>
          <?php $i++; ?>
        <?php ?>
      <?php ?>  
</select>
   
Code: [Select]
<?php $regions RegionStats :: newInstance()->listRegions('%%%%''>''items DESC'); ?>
      <?php $i 1?>
<select name="sRegion" id="sRegion" onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
<option value="">Select a region</option> 
      <?php foreach($regions as $r) { ?>
        <?php if($i <= 30) { ?>
<option value="<?php echo osc_search_url(array('page' => 'search''sRegion' => $r['region_id']));?>"><?php echo $r['region_name']; ?> (<?php echo $r['items']; ?>)</option>
          <?php $i++; ?>
        <?php ?>
      <?php ?>  
</select>
« Last Edit: May 09, 2022, 03:11:21 PM by MB Themes »

*

MB Themes

Re: Menu based on the selection of cities or regions
« Reply #3 on: May 09, 2022, 03:11:41 PM »
@Fantasy
Thanks ;)
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

casper

  • ***
  • 48 posts
Re: Menu based on the selection of cities or regions
« Reply #4 on: May 11, 2022, 05:57:32 AM »
Thanks for the solution

Can this be done on categories?

*

Fantasy

  • **
  • 7 posts
Re: Menu based on the selection of cities or regions
« Reply #5 on: May 11, 2022, 06:08:35 AM »
<?php
          osc_goto_first_category();
          $i = 1;
        ?>
<select name="sCategory" id="sCategory" onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
<option value="">Category</option>
          <?php while(osc_has_categories()) { ?>
            <?php if($i <= 10) { ?>
         <option value="<?php echo osc_search_url(array('page' => 'search', 'sCategory' => osc_category_id())); ?>"><?php echo osc_category_name();?> <?php if(osc_category_total_items()>0){ echo '('.osc_category_total_items().')';} ?></option>          
            <?php } ?>
            <?php $i++; ?>
          <?php } ?>
</select>

*

casper

  • ***
  • 48 posts
Re: Menu based on the selection of cities or regions
« Reply #6 on: May 11, 2022, 09:50:08 AM »
<?php
          osc_goto_first_category();
          $i = 1;
        ?>
<select name="sCategory" id="sCategory" onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
<option value="">Category</option>
          <?php while(osc_has_categories()) { ?>
            <?php if($i <= 10) { ?>
         <option value="<?php echo osc_search_url(array('page' => 'search', 'sCategory' => osc_category_id())); ?>"><?php echo osc_category_name();?> <?php if(osc_category_total_items()>0){ echo '('.osc_category_total_items().')';} ?></option>          
            <?php } ?>
            <?php $i++; ?>
          <?php } ?>
</select>

Thanks for your quick response and the amazing result.

Excellent it works  ::)

*

casper

  • ***
  • 48 posts
Re: Menu based on the selection of cities or regions
« Reply #7 on: May 11, 2022, 10:06:22 AM »
Code: [Select]
<?php $regions RegionStats :: newInstance()->listRegions('%%%%''>''items DESC'); ?>
      <?php $i 1?>
<select name="sRegion" id="sRegion" onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
<option value="">Select a region</option>
      <?php foreach($regions as $r) { ?>
        <?php if($i <= 30) { ?>
<option value="<?php echo osc_search_url(array('page' => 'search''sRegion' => $r['region_id']));?>"><?php echo $r['region_name']; ?> (<?php echo $r['items']; ?>)</option>
          <?php $i++; ?>
        <?php ?>
      <?php ?>
</select>

The code for cities works as well, but the code for the regions does not display the regions!
What is the reason in your opinion?

*

MB Themes

Re: Menu based on the selection of cities or regions
« Reply #8 on: May 11, 2022, 05:33:39 PM »
Review region stats table
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

casper

  • ***
  • 48 posts
Re: Menu based on the selection of cities or regions
« Reply #9 on: May 11, 2022, 10:21:23 PM »
Review region stats table

Thank you, the site stats have been recalculated and the code is now working fine

thank you again

*

MB Themes

Re: Menu based on the selection of cities or regions
« Reply #10 on: May 11, 2022, 10:35:51 PM »
Cool  :P
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots