Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1007721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:39:39+00:00 2026-05-16T08:39:39+00:00

I have an application in CakePHP that lists businesses. I have a business model/controller,

  • 0

I have an application in CakePHP that lists businesses. I have a business model/controller, as well as a state_list model/controller. However I want to be more detailed so when a user clicks on a State page, it lists all the cities in that particular State that businesses are listed in.
Then when they click a particular city it then shows a page listing all the businesses in that particular city.

How would I be able to do this without a database table of a listing of all cities?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:39:40+00:00Added an answer on May 16, 2026 at 8:39 am

    For this purpose a better database structure would be something along the lines of this:

    Table: Location
    id
    parent_id
    name
    type
    
    Table: Business
    id
    location_id
    ...
    

    Your cities and states should form a tree:

    America
       California
          San Francisco
       New York
          ...
    Japan
       Tokyo
          ...
    

    For example:

    Business ( ..., location_id => 5, ... )
    Location ( id => 5, parent_id => 2, name => San Francisco, type => city )
    Location ( id => 2, parent_id => ..., name => California, type => state )
    

    That way each business belongs to a city and implicitly to a state and a country as well and everything has a nice id. You also can’t make the mistake of having a business that’s in New York, California, Japan (which is currently possible).

    Given what you have you can only filter cities via a name search:

    $listOfBusinessesInState = $this->Business->find('all', array(
        'conditions' => array('Business.state_id' => $state_id),
        'fields'     => array('Business.city'),
        'group'      => array('Business.city')
    ));
    $listOfCitiesInState = Set::extract('/Business/city', $listOfBusinessesInState);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built an application in CakePHP that lists businesses. There are about 2000
I have a CakePHP 1.3 application that has a login system, which works well.
I developed small CakePHP application, and now I want to add one more table
I have a CakePHP Application which I want to protect with a password. The
I have a CakePHP application that uses a number of vendor classes, including one
I have developed a CakePHP application that does basic CRUD on a series of
I have a cakePHP application that is pulling data from two different databases, which
I have a CakePHP application that allows a user to register and post projects.
So I have this one CakePHP web application that I'm trying to refactor. There
I'm building a prototype search application using CakePHP and I have a search controller

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.