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 8039753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:40:34+00:00 2026-06-05T03:40:34+00:00

I am showing some listings on a page by location using the following query:

  • 0

I am showing some listings on a page by location using the following query:

SELECT *,
 ((ACOS(SIN($lat * PI() / 180) * SIN(gps_lat * PI() / 180) + COS($lat * PI() / 180) * COS(gps_lat * PI() / 180) * COS(($lon - gps_long) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS distance 
  FROM listings

I would like to now also filter the above listings by their building type. A separate table records the listing id and the building type id as below:

SELECT * 
  FROM building_types_listings 
 WHERE listing_id = listings.id 
   AND building_type_id = '$building_type'

How can I incorporate both queries into one SQL statement?

  • 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-05T03:40:36+00:00Added an answer on June 5, 2026 at 3:40 am

    Try something like:

    SELECT whatever fields you need,
           ((ACOS(SIN($lat * PI() / 180) * SIN(gps_lat * PI() / 180) + COS($lat * PI() / 180) * COS(gps_lat * PI() / 180) * COS(($lon - gps_long) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS distance
    FROM listings
      JOIN building_types_listings
        ON listings.id = building_types_listings.listing_id
    WHERE building_type_id = '$building_type'
    

    However, you definitely want to rethink how you’re building your queries and inserting strings into them. What would happen if $building_type is exactly (minus double quotes) “‘;DELETE FROM listings;– “? I recommend you rely on some sprintf-like facility (in PHP it often means you’ll need prepared statements) rather than the deprecated misfeature magic quotes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am try to bind the dropdowmlist using jquery. But is showing some error.
My page showing error forbidden access error, when I post some html and javascript
hi friends i have i am showing some data via ajax on my page
I'm using a DataGridView in a Windows application (.NET 3.5) showing some colored bars
In my main page, I have a div showing some external html content. Here
I'am using a Flexicious Datagrid for showing some basic information. This datagrid has a
Am using RichTextBox in a C#/Winforms application. Am showing some text in this control
I have the following code for showing some images: HTML: <div class=footer-logos> <ul> <li><img
I am using jquery accordion in my application. I am showing some links in
I have a DataGrid that is showing some data via a PagedCollectionView with one

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.