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

  • SEARCH
  • Home
  • 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 8282627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:26:15+00:00 2026-06-08T10:26:15+00:00

For a real estate website I need to implement a search mechanism that allows

  • 0

For a real estate website I need to implement a search mechanism that allows to search both for text and distance.
Doing distance calculations on a MySQL table when the lat & lon are recorded in separate columns is easy but a house tends to have a LOT of true/false properties.

I will need to store all those fields in a database because they need to be editable so I intend to use a simple table like | houseID | property | in which I store all properties that are true (set).

That will save me from making a ridiculously wide table with hundreds of columns, but searching this database will not be very feasible.

I have thought about adding a column of type text to each house’s main record that contains the fieldnames of all true properties. I would then search both the human text description and that text column but I feel that’s still not the best approach.

How could I solve this in a clean way?

Thanks in advance!

  • 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-06-08T10:26:17+00:00Added an answer on June 8, 2026 at 10:26 am

    I would reccomend the Entity Attribute Value or EAV model of storing data. http://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model (this is how WordPress Posts and Post Meta work).

    so assuming tables like:

    ENTITY_TABLE: (id,title,author,content,date_created,date_modified)
    ATTRIBUTE_TABLE: (id, entity_id, akey, avalue)
    

    Use a query like this:

    SELECT e.*, 
        MAX( IF(m.akey= 'has_ac', m.avalue, 0) ) as 'has_ac', 
        MAX( IF(m.akey= 'has_garage', m.avalue, 0) ) as 'has_garage', 
        MAX( IF(m.akey= 'has_fridge', m.avalue, 0) ) as 'has_fridge', 
        MAX( IF(m.akey= 'latitude', m.avalue, 0) ) as 'latitude', 
        MAX( IF(m.akey= 'longitude', m.avalue, 0) ) as 'longitude'
    FROM ENTITY_TABLE e
    JOIN ATTRIBUTE_TABLE m ON e.id = m.entity_id
    WHERE has_ac=1
    

    that will select entities and their related attributes (has_ac, has_garage, has_fridge, latitude, and longitude) and require that all entities selected will have has_ac equal to 1 (true)

    Now for the geo stuff:

    SELECT e.*, 
        MAX( IF(m.akey= 'has_ac', m.avalue, 0) ) as 'has_ac', 
        MAX( IF(m.akey= 'has_garage', m.avalue, 0) ) as 'has_garage', 
        MAX( IF(m.akey= 'has_fridge', m.avalue, 0) ) as 'has_fridge', 
        MAX( IF(m.akey= 'latitude', m.avalue, 0) ) as 'latitude', 
        MAX( IF(m.akey= 'longitude', m.avalue, 0) ) as 'longitude',
        (
            3959 * 
            acos(
                cos( radians( MAX( IF(m.akey= 'latitude', m.avalue, 0) ) ) ) * 
                cos( radians( CUSTOMER_LAT ) ) * 
                cos( radians( CUSTOMER_LONG ) - radians( MAX( IF(m.akey= 'longitude', m.avalue, 0) ) ) ) + 
                sin( radians( MAX( IF(m.akey= 'latitude', m.avalue, 0) ) ) ) * 
                sin( radians( CUSTOMER_LAT ) ) 
            ) 
        ) AS distance
    FROM ENTITY_TABLE e
    JOIN ATTRIBUTE_TABLE m ON e.id = m.entity_id
    WHERE has_ac=1
    ORDER BY distance ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I am working on one Real Estate Website, In that website I
I need this map widget on my real estate website. I have seen it
I have a real estate website that has several categories. And i want the
Im making a real estate site and need a search form similar to one
I'm building a real-estate site where my visitors need to search based on ranges.
Our real estate website sends email notifications when properties come on the market matching
I am working on a real estate website and I am using a datalist
I am working on one real estate website which is Using RETS service to
I'm using a SQL Server database, I'm working on a real estate website. I
Given a MySQL table of real estate data, I would like to generate a

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.