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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:53:36+00:00 2026-05-26T13:53:36+00:00

I’m making a site where the user can select a rental property that has

  • 0

I’m making a site where the user can select a rental property that has two fields they can select from, Furnished and Pets. The options in both select boxes is Yes and No.

<select name="furnished">
  <option value="">
  <option value="yes">Yes</option>
  <option value="no">No</option>
</select>

<select name="pets">
  <option value="">
  <option value="yes">Yes</option>
  <option value="no">No</option>
</select>

I am writing a SQL statement based on what the user picks in those fields.

$sql = 'SELECT *
       FROM properties
       WHERE num_bedrooms >= ' . $_GET['num_bedrooms'] . 
       ' AND num_bathrooms >= ' . $_GET['num_bathrooms'];

if($_GET['furnished'] == 'yes') { //if the furnished is set to yes
  $sql .= ' AND furnished = "yes" OR furnished = "partially"';
} else if($_GET['furnished'] == 'no') { //if the furnished is set to no
  $sql .= ' AND furnished = "no" OR furnished = "description"';
} 

if($_GET['pets'] == 'yes') { //if the pets is set to yes
  $sql .= ' AND pets = "yes" OR pets = "cats" OR pets = "dogs"';
} else if($_GET['pets'] == 'no') { //if the pets is set to no
  $sql .= ' AND pets = "no" OR pets = "description"';
}

If the user chooses yes for furnished, I want it to display all properties that are furnished (yes) OR that are partially furnished(partially). If the user chooses No, I want it to display all properties that are not furnished(no) OR that have a special description(description).

If the user chooses yes for pets, I want it to display all properties that allow all pets (yes) OR that allow only cats(cats) OR that allow only dogs(dogs). If the user chooses No, I want it to display all properties that don’t allow pets(no) OR that have a special description(description).

As an example, this is the outputted SQL statement if the user chooses Yes on Furnished and Yes on Pets:

SELECT * FROM properties 
WHERE num_bedrooms >= 1 
AND num_bathrooms >= 1 
AND furnished = "yes" OR furnished = "partially" 
AND pets = "yes" OR pets = "cats" OR pets = "dogs"

The problem is that it will currently return results that meet EITHER of the furnished or pets requirements in the where clause, whereas I need it to return results that meet BOTH of the furnished and pets requirements in the where clause.

So it will currently return a result that says has the Furnished set to yes, and the pets set to no.
How can I have it return all results with furnished set to yes AND pets set to yes?

What is wrong with my 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-05-26T13:53:37+00:00Added an answer on May 26, 2026 at 1:53 pm

    AND comes before OR in operator precedence, so your query reads like

    SELECT * FROM properties 
    WHERE 
    (num_bedrooms >= 1 AND num_bathrooms >= 1 AND furnished = "yes")
    OR (furnished = "partially" AND pets = "yes")
    OR pets = "cats" 
    OR pets = "dogs"
    

    which is not quite what you expected. Try

    SELECT * FROM properties 
    WHERE num_bedrooms >= 1 
    AND num_bathrooms >= 1 
    AND (furnished = "yes" OR furnished = "partially")
    AND (pets = "yes" OR pets = "cats" OR pets = "dogs")
    

    or even better

    SELECT * FROM properties 
    WHERE num_bedrooms >= 1 
    AND num_bathrooms >= 1 
    AND furnished IN ("yes", "partially")
    AND pets IN ("yes", "cats", "dogs")
    

    You shouldn’t do SELECT * try naming the columns you need!

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

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.