Loading


Advertisement:

Author Topic: Display locations  (Read 227 times)

tom89pl

  • Newbie
  • *
  • Posts: 1
Display locations
« on: October 23, 2017, 01:23:18 am »
i would like display locations like country>region>city but my code not working, can someone help me?

Code: [Select]
<?php 


$locations = array();
if(
osc_count_list_cities() > ) {

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


?>




                            <ul>

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

<?php print_r (osc_list_country_code()); ?>

                                <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();
$regio Region::newInstance()->findByPrimaryKey($region_id);
$region_code $regio['fk_c_country_code'];
        echo 
'<li>' $region_code '<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>' $region_code '<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

  • issues
  • Hero Member
  • *
  • Posts: 1158
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1158
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Display locations
« Reply #2 on: December 21, 2017, 04:54:54 pm »
Teseo, can you please see the code from here https://forums.osclass.org/3-7-x/how-to-list-all-cities-with-ads-under-all-regions/msg158691/#msg158691 and the reason why it displays 

   
"Warning: Invalid argument supplied for foreach()" foreach($locationsRegions[$country_code] as $regionId => $aregion) {

in Osclass 3.5.7?

In 3.7.x it workes fine.

teseo

  • Hero Member
  • *****
  • Posts: 6015
Re: Display locations
« Reply #3 on: December 21, 2017, 05:17:10 pm »
Hi,

I don't have a 3.5.7 installation to test this. Anyway, in Osclass 3.7.4 your code only gives me Countries, to get regions and cities stats i had to replace this line:

Code: [Select]
$country_code = osc_list_country_code();
with

Code: [Select]
$country_code = strtolower(osc_list_country_code());
It might be related to your issue on 3.5.7 ???

Regards

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1158
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Display locations
« Reply #4 on: December 21, 2017, 09:05:03 pm »
Thank you Teseo. Why the country code is not the same in cities , regions and country? I mean "De" "de" or "DE".

teseo

  • Hero Member
  • *****
  • Posts: 6015
Re: Display locations
« Reply #5 on: December 21, 2017, 11:56:29 pm »
Well, I'm not sure why, but I do have in t_region tables country codes with mixed format (some of them uppercase, some lowercase). ???

In any case, MySQL is case-insensitive, but PHP names of array indexes aren't, so I guess for this code it would be prudent to first convert any country code taken from the database to the same standard (everything uppercase or everything lowercase).

Regards