Advertisement:

Author Topic: Popular Cities  (Read 3902 times)

jonh1052

  • Newbie
  • *
  • Posts: 14
Popular Cities
« on: June 06, 2012, 04:46:36 am »
Hi

I am wanting to add on the right side of my site Popular Cities (top 10). Would anyone know how to do?

My site: www.kdanuncios.com.br


Tanks

jonh1052

  • Newbie
  • *
  • Posts: 14
Re: Popular Cities
« Reply #1 on: June 06, 2012, 11:28:32 pm »
Can you help me?

mrnestyy

  • Newbie
  • *
  • Posts: 1
How can i add City/Region in sidebar
« Reply #2 on: June 07, 2012, 12:59:13 am »
hi guys,
I am new to osclass and in am looking for tips on adding city or region to my sidebar.Nothing seems to show after i have uploaded and installed OSClass.

jonh1052

  • Newbie
  • *
  • Posts: 14
Re: Popular Cities
« Reply #3 on: June 11, 2012, 09:27:15 pm »
help me please!

fre2mansur

  • Hero Member
  • *****
  • Posts: 711
Re: Popular Cities
« Reply #4 on: March 18, 2015, 03:01:06 pm »
Still no solution??

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Popular Cities
« Reply #5 on: March 18, 2015, 07:22:26 pm »
***CORRECTED***

Hi,

Code: [Select]
    <?php $conn getConnection();
    
$popular_cities $conn->osc_dbFetchResults("SELECT c.s_name as city_name, cs.i_num_items as items
     FROM %st_city_stats cs
     INNER JOIN %st_city c ON c.pk_i_id = cs.fk_i_city_id
     WHERE cs.i_num_items > 0
     ORDER BY cs.i_num_items DESC
     LIMIT 10"
DB_TABLE_PREFIXDB_TABLE_PREFIX);

    
View::newInstance()->_exportVariableToView('cities'$popular_cities);

    while(
osc_has_cities()) {
        echo 
osc_city_name() . ' (' osc_city_items() . ')<br />';
    } 
?>


Regards
« Last Edit: March 18, 2015, 09:01:30 pm by teseo »

fre2mansur

  • Hero Member
  • *****
  • Posts: 711
Re: Popular Cities
« Reply #6 on: March 18, 2015, 08:00:02 pm »
hmm something wrong with this code page does not load at all.

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Popular Cities
« Reply #7 on: March 18, 2015, 08:13:55 pm »
No, the code is right. You must have inserted in the wrong place, eliminate php start <?php and end ?> tags if you are inserting it inside another block of PHP code.

Regards

fre2mansur

  • Hero Member
  • *****
  • Posts: 711
Re: Popular Cities
« Reply #8 on: March 18, 2015, 08:53:49 pm »
Yes i'm placed in wrong place but now I'm corrected. but the code does not showing any cities.
« Last Edit: March 18, 2015, 08:57:25 pm by fre2mansur »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Popular Cities
« Reply #9 on: March 18, 2015, 09:03:25 pm »
There was a little mistake, it wouldn't work if your tables have other prefix than standard "oc_", try now with my corrected code above.

If still failing, paste here your footer.php

fre2mansur

  • Hero Member
  • *****
  • Posts: 711
Re: Popular Cities
« Reply #10 on: March 18, 2015, 09:18:20 pm »
no. its working well. I cant make this topic as solved. anyway thank you teseo. ;)

This code how I before use the popular cities with using  jquery. but teseo mthode is better.

Code: [Select]
<?php if(osc_count_list_cities() > 0) { ?>
                <h4><?php _e('Popular Cities''bender'); ?></h4>
               <div class="popcity">
                    <ul class="popcity">
                             <?php while(osc_has_list_cities() ) { ?>
                                <li><a href="<?php echo osc_list_city_url(); ?>"> <i class="hidden"><?php echo osc_list_city_items() ; ?></i> <?php echo osc_list_city_name() ; ?></a></li>
                             <?php ?>
                            </ul>
                        <?php ?>
                        <script>
                            $(function(){
                                var elems = $('ul.popcity').children('li').remove();
                                elems.sort(function(b,a){
                                    return parseInt($(a).text()) > parseInt($(b).text());
                                });
                                $('ul.popcity').append(elems);
                                $('ul.popcity li:eq(4)').nextAll().remove();
                            });
                        </script>
« Last Edit: March 18, 2015, 09:19:54 pm by fre2mansur »

MkRahamath

  • Jr. Member
  • **
  • Posts: 73
Re: Popular Cities
« Reply #11 on: February 08, 2017, 12:46:59 pm »
How to make below code for countires and Possible make this as New DAO method?

***CORRECTED***

Hi,

Code: [Select]
    <?php $conn getConnection();
    
$popular_cities $conn->osc_dbFetchResults("SELECT c.s_name as city_name, cs.i_num_items as items
     FROM %st_city_stats cs
     INNER JOIN %st_city c ON c.pk_i_id = cs.fk_i_city_id
     WHERE cs.i_num_items > 0
     ORDER BY cs.i_num_items DESC
     LIMIT 10"
DB_TABLE_PREFIXDB_TABLE_PREFIX);

    
View::newInstance()->_exportVariableToView('cities'$popular_cities);

    while(
osc_has_cities()) {
        echo 
osc_city_name() . ' (' osc_city_items() . ')<br />';
    } 
?>


Regards

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Popular Cities
« Reply #12 on: February 08, 2017, 04:29:21 pm »
***CORRECTED***

Hi,

Using DAO method:

Code: [Select]
$popularCities = new DAO();

$popularCities->dao->select('c.s_name as city_name, cs.i_num_items as items');
$popularCities->dao->from(DB_TABLE_PREFIX.'t_city_stats cs');
$popularCities->dao->join(DB_TABLE_PREFIX.'t_city c', 'c.pk_i_id = cs.fk_i_city_id', "INNER");
$popularCities->dao->where('cs.i_num_items > 0');
$popularCities->dao->orderBy('cs.i_num_items', 'DESC');
$popularCities->dao->limit(0, 10);

$result = $popularCities->dao->get();
$popular_cities = $result->result();

    View::newInstance()->_exportVariableToView('cities', $popular_cities);

    while(osc_has_cities()) {
        echo osc_city_name() . ' (' . osc_city_items() . ')<br />';
    }
 

For countries I've answered in this other thread of yours:

http://forums.osclass.org/general-help/popular-countries

Regards
« Last Edit: February 08, 2017, 06:32:28 pm by teseo »

MkRahamath

  • Jr. Member
  • **
  • Posts: 73
Re: Popular Cities
« Reply #13 on: February 08, 2017, 06:16:41 pm »
This is not working and nothing display.

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Popular Cities
« Reply #14 on: February 08, 2017, 06:33:04 pm »
Yes, there was a bug, try now my corrected code.