how to show city if products is listed in that city

I have an ecommerce (php) deal website using cities. I have all cities in database already. Instead of all cities are listed out as a dropdown list for choosing, what I want to custom is only show whatever city if there is product listed or available in that city. For example, I have all of these cities in database Sacramento, Los Angeles, Seatle, New York, Chicago, Portland. But currently there are only deals listing in Sacramento, Los Angeles, and New York, so I want to show these 3 cities only instead of all. So can anyone help or suggest me codes to do it?

Below is the current code that shows all of the cities for users to choose”

<div class="city_cat">
  <?php if (CITY_SETTING) { ?>
      <?php $city_name="" ; foreach ($this->all_city_list as $c) { if ($c->city_id == $this->session->get('CityID')) { $city_name = $c->city_name; } } ?>
      <a style="cursor:pointer;" title="<?php echo ucfirst($city_name); ?>">
        <?php echo ucfirst($city_name); ?>
      <div class="drop_down1">
          <?php foreach ($this->all_country_list as $country) { ?>

          <?php foreach ($this->all_city_list as $city) { if ($country->country_id == $city->country_id) { ?>

            <a style="cursor:pointer;" onclick="return changecity('<?php echo $city->city_id; ?>', '<?php echo $city->city_url; ?>');" title="<?php echo ucfirst($city->city_name); ?>">
              <?php echo $city->city_name; ?></a>

          <?php } } ?>

          <?php } ?>


Source: mysql

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.