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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:59:44+00:00 2026-06-02T16:59:44+00:00

I have a PHP document that query’s a MYSQL database based on the input

  • 0

I have a PHP document that query’s a MYSQL database based on the input values from a search form. Everything is working perfectly except I am struggling to add one more feature which I believe would make the entire application much more user friendly.

My table in my database is basically storing information on a variety of social clubs. It has data regarding their location, name, booking_price, alcohol_permitted. The bit I need help with is associated with alcohol_permitted. In the database its stores 1 or 2, 2 meaning yes alcohol is permitted and 1 meaning no its not.

Currently my form looks like this:

<form>
    <label for="alcohol_check">Search clubs where alcohol permitted?</label>
       <input type="radio" id="alcohol_check1" value="1" /><label for="radio1">No</label>
       <input type="radio" id="alcohol_check2" value="2" /><label for="radio2">Yes</label>
       <input type="radio" id="alcohol_check3" value="???" /><label for="radio3">Show both</label>

    <label for="club_name">Enter social club name:</label>
       <input type="text" id="club_name" name="club_name"/>
</form>

My PHP looks like this:

$user_alcohol_permitted_selection = $_POST['alcohol_check']; //Value sent using jquery .load()
$user_social_club_name_input = $_POST['name']; //Value sent using jquery .load()

$query="SELECT * FROM social_clubs 
        WHERE name = $user_social_club_name_input
        AND
        WHERE alcohol_permitted = $user_alcohol_permitted_selection";

The problem is at the moment, my query will only retrieve social clubs that either serve alcohol or don’t. Because the values passed at the moment from the alcohol_permitted form are either 1 or 2.
What can I do to my query so that if the user selects option ‘both’, it retrieves social clubs that serve alcohol and clubs that don’t? I cant figure it out! Do I need an if statement in my query?

Thanks for checking this out, sorry if I didn’t explain this very well.

  • 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-02T16:59:46+00:00Added an answer on June 2, 2026 at 4:59 pm

    This should work.

    $user_alcohol_permitted_selection = $_POST['alcohol_check']; //Value sent using jquery .load()
    $user_social_club_name_input = $_POST['name']; //Value sent using jquery .load()
    
    $query="SELECT * FROM social_clubs 
            WHERE name = $user_social_club_name_input";
    
    if ($user_alcohol_permitted_selection == "???")
    {
         $query.= "AND WHERE alcohol_permitted = 1 OR alcohol_permitted = 2";
    } else {
         $query.= "AND WHERE alcohol_permitted = $user_alcohol_permitted_selection";
    }
    

    Additionally if column alcohol_permitted contains only values 1 or 2. I’d suggest you change the column type to bool like therealmitchconnors suggested in his answer.

    Then, you can trim down the conditional statement to:

    $query="SELECT * FROM social_clubs 
            WHERE name = $user_social_club_name_input";    
    
    if ($user_alcohol_permitted_selection != "???")
    {
         $query.= "AND WHERE alcohol_permitted = $user_alcohol_permitted_selection";
    }
    

    Please note the !.

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

Sidebar

Related Questions

I have a php page that pulls data from a mysql database based on
I have an AJAX script that receives a string from a mySQL query returned
I have a table created with PHP from an Sql Database that successfully displays
I have a php page that displays rows from a mysql db as a
I have a DIV that contains paginated results of a MySQL query. I was
I'm creating a php website in which I have a document.php that basically takes
I have a jQuery search script that queries a PHP file then parses the
I have a HTML document that I want to remove specific tags from, identified
I have a Google Instant style jQuery search script that queries a PHP file
I have a Google Instant style jQuery search script that queries a PHP file

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.