1

How can I display regions and their cities only with ads? And why I can't see numbers of ads? I would like use jQuery but I don't know how.

<?php
              $aRegions = Region::newInstance()->getByCountry('AT');
              if(count($aRegions) > 0 ) { ?>
                <ul>
              <?php
                foreach($aRegions as $region) {
                //print_r ($region);
                echo "<li>";
                 //$region['pk_i_id'].
                ?>
                <div class="accordionButton">
                 <a href="javascript:void()">
                  <?php echo $region['s_name']."\n"; ?>
                 </a>
                 <?php // echo "</em>(". $region['items'].")</em>";?>
                 </div>
                  <?php
                  $aCities = City::newInstance()-> getByRegion($region['pk_i_id']);
                  if(count($aCities) > 0 ) { 
                  echo "<div class=\"accordionContent\">";
                  echo "<ul>";
                      foreach($aCities as $city)  { 
                    //  print_r ($city);
                                                //$city["pk_i_id"].'
                        echo "<li>";
                        echo  "<a href='". osc_search_url( array( 'sRegion'=>$region["s_name"], 'sCity' => $city['s_name']  ) ) ."'> ";
                        echo $city["s_name"]."\n";
                        echo "</em>(". $city['items'].")</em>";
                        echo "</a>";
                        echo "</li>";
                        }
                      }
                       echo "</ul>";
                 echo "</li>";
                  } ?>
            </ul>
            <?php
              }
            ?>
halfer
  • 19,824
  • 17
  • 99
  • 186
Tomasz
  • 27
  • 8

4 Answers4

1

The solution for cities is:

        <?php if(osc_count_list_cities() > 0 ) { ?>
            <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 } ?>

Now it's tested and workes for cities This will list all cities and their number of items.

marius-ciclistu
  • 448
  • 4
  • 14
  • I've opened a topic in here https://forums.osclass.org/3-7-x/how-to-list-all-cities-with-ads-under-all-regions/msg156255/#msg156255 asking for help regarding showing region + cities with their ads. – marius-ciclistu Sep 30 '17 at 23:20
0

The solution for regions > cities is:

$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'];
        $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>';

}
marius-ciclistu
  • 448
  • 4
  • 14
  • Thanks! Your code is good! I need to rewrite it now for country display. This is my code but does not work properly, instead of showing German regions this code display austrian regions again: – Tomasz Oct 10 '17 at 18:10
  • I posted the answer for your new question, that includes all the countries. – marius-ciclistu Dec 13 '17 at 17:40
0

Thanks! Your code is good! I need to rewrite it now for country display. This is my code but does not work properly, instead of showing German regions this code display austrian regions again:

<?php 


$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'];
    $locations[$region_id][$city_id] = array("cityurl"=>osc_list_city_url(), "cityname"=>osc_list_city_name(), "cityitems"=>osc_list_city_items());
}
?>
                            <ul>

                 <?php       while(osc_has_countries() ) { ?>

                            <li><a href="<?php echo osc_country_url( array( 'sCountry' => osc_list_country_code() ) ) ; ?>"><?php echo osc_country_name() ; ?> <em>(<?php echo osc_country_items() ; ?>)</em></a>





                        <?php  if (osc_country_name() =='Austria')  { ?>
<?php                       
echo '<ul>';
while(osc_has_list_regions('AT') ) {  
    $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>';

                        }


                 if (osc_country_name() =='Germany')  { ?>
<?php                       
echo '<ul>';
while(osc_has_list_regions('DE') ) {  
    $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>';
                 }
                 }

} ?>
Tomasz
  • 27
  • 8
0

The solution for COUNTRIES > REGIONS > CITIES in Osclass 3.7.x is

    $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 = strtolower($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 = strtolower($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 = strtolower(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>';

    }
marius-ciclistu
  • 448
  • 4
  • 14