Advertisement:

Author Topic: SOLVED How to list all cities with ads under all regions? + under all countries  (Read 1003 times)

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Hi.
I tried:

Code: [Select]
<ul>
    <?php while(osc_has_list_regions() ) { ?>
        <li><a href="<?php echo osc_list_region_url(); ?>"><?php echo osc_list_region_name() ; ?> <em>(<?php echo osc_list_region_items() ; ?>)</em></a>
            <ul>
            <?php while(osc_has_cities() ) { ?>
               <li><a href="<?php echo osc_list_city_url(); ?>"><?php echo osc_list_city_name() ; ?> <em>(<?php echo osc_list_city_items() ; ?>)</em></a></li>
            <?php ?>
           </ul>
        </li>
    <?php ?>
</ul>

But this code doesn't seem to work...
Code: [Select]
            <?php while(osc_has_cities() ) { ?>
               <li><a href="<?php echo osc_list_city_url(); ?>"><?php echo osc_list_city_name() ; ?> <em>(<?php echo osc_list_city_items() ; ?>)</em></a></li>
            <?php ?>
« Last Edit: December 13, 2017, 09:00:16 pm by marius-ciclistu »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: How to list all cities with ads under all regions?
« Reply #1 on: October 01, 2017, 02:06:10 am »
This workes by listing all cities under each region....

Code: [Select]
<?php if(osc_count_list_regions() > ) { ?>
<ul>
    <?php while(osc_has_list_regions() ) { ?>
        <li><a href="<?php echo osc_list_region_url(); ?>"><?php echo osc_list_region_name() ; ?> <em>(<?php echo osc_list_region_items() ; ?>)</em></a>
        <?php if(osc_count_list_cities() > ) { ?>
            <ul>
            <?php while(osc_has_list_cities() ) { ?>
               <li><a href="<?php echo osc_list_city_url(); ?>"><?php echo osc_list_city_name() ; ?> <em>(<?php echo osc_list_city_items() ; ?>)</em></a></li>
            <?php ?>
           </ul>
        <?php ?>
        </li>
    <?php ?>
</ul>
<?php ?>
« Last Edit: October 01, 2017, 02:20:13 am by marius-ciclistu »

Darwazo

  • Full Member
  • ***
  • Posts: 113
Re: NOT SOLVED How to list all cities with ads under all regions?
« Reply #2 on: October 01, 2017, 04:50:54 am »
Hi Marius...thank you for the code !!

I thought this code is for selection ALL REGIONS AND ALL CITIES within REGION AND CITIES OPTION WHILE Posting an add.

Ideally theme should had builtin feature like ALL REGIONS and CITIES while posting an add :(






marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: NOT SOLVED How to list all cities with ads under all regions?
« Reply #3 on: October 01, 2017, 10:11:22 am »
Hi. No. It's for showing the locations that have ads in them, but I didn't figure out yet how to show cities grouped by regions.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: SOLVED How to list all cities with ads under all regions?
« Reply #4 on: October 05, 2017, 01:01:41 pm »
I figured it out

Code: [Select]
if(osc_count_list_cities() > 0 ) {
$locations = array();
    while(osc_has_list_cities() ) {
        $city_id = osc_list_city_id();
        $city = City::newInstance()->findByPrimaryKey($city_id);
        $region_id = $city['fk_i_region_id'];
        $locations[$region_id][$city_id] = array("cityurl"=>osc_list_city_url(), "cityname"=>osc_list_city_name(), "cityitems"=>osc_list_city_items());
    }
    echo '<ul>';
    while(osc_has_list_regions() ) { 
        $region_id = osc_list_region_id();
        echo '<li><a href="' . osc_list_region_url() . '">' . osc_list_region_name() . '<em>(' . osc_list_region_items() . ')</em></a>' ;
        echo '<ul>';
        foreach($locations[$region_id] as $acity) {
            echo '<li><a href="' . $acity['cityurl'] . '">' . $acity['cityname'] . '<em>(' . $acity['cityitems'] . ')</em></a></li>' ;
        }
        echo '</ul></li><br/>';
       
    }
    echo '</ul>';

}
« Last Edit: October 05, 2017, 01:31:20 pm by marius-ciclistu »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: SOLVED How to list all cities with ads under all regions?
« Reply #5 on: December 13, 2017, 08:59:53 pm »
The solution for all countries > regions > cities that have items is:
Osclass 3.7.x

Code: [Select]
    $locations = array();
    if(osc_count_list_cities() > 0 ) {

        while(osc_has_list_cities() ) {
        $city_id = osc_list_city_id();
        $city = City::newInstance()->findByPrimaryKey($city_id);
        $region_id = $city['fk_i_region_id'];
        $country_code = $city['fk_c_country_code'];
        $locations[$country_code][$region_id][$city_id] = array("cityurl"=>osc_list_city_url(), "cityname"=>osc_list_city_name(), "cityitems"=>osc_list_city_items());
        }
    $locationsRegions = array();
        while(osc_has_list_regions() ) {
        $region_id = osc_list_region_id();
        $region = Region::newInstance()->findByPrimaryKey($region_id);
        $country_code = $region['fk_c_country_code'];
        $locationsRegions[$country_code][$region_id] = array("regionurl"=>osc_list_region_url(), "regionname"=>osc_list_region_name(), "regionitems"=>osc_list_region_items());
        }

    echo "<ul>";
    while(osc_has_list_countries() ) {
        $country_code = osc_list_country_code();
        echo '<li><a href="' . osc_list_country_url() . '">' . osc_list_country_name() . '<em>(' . osc_list_country_items() . ')</em></a>' ;
        echo '<ul>';
        foreach($locationsRegions[$country_code] as $regionId => $aregion) {
            echo '<li>';
            echo '<a href="' . $aregion['regionurl'] . '">' . $aregion['regionname'] . '<em>(' . $aregion['regionitems'] . ')</em></a></br>' ;
            echo '<ul>';
            foreach($locations[$country_code][$regionId] as $acity) {
                echo '<li><a href="' . $acity['cityurl'] . '">' . $acity['cityname'] . '<em>(' . $acity['cityitems'] . ')</em></a></li>' ;
            }
            echo '</ul></li><br/>';
        }
        echo '</ul></li><br/>';


        }
        echo '</ul>';

    }
« Last Edit: December 21, 2017, 04:53:19 pm by marius-ciclistu »