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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:17:20+00:00 2026-05-30T01:17:20+00:00

For weeks on end I have worked on MYSQL and PHP. I have built

  • 0

For weeks on end I have worked on MYSQL and PHP. I have built a music database with approx 15 data columns. MANUALLY – I am able to QUERY database with great results:

SELECT * FROM $tableName WHERE category RLIKE ('option-choice') and
genre RLIKE ('option-choice') and Sub_genre RLIKE ('option-choice')
and lyrical_theme RLIKE ('option-choice') and lead RLIKE
('option-choice') and tempo RLIKE ('option-choice'); "

My available HTML FORM has NINE drop down buttons which I want to perform as well, each containing several choices. No radio buttons, check boxes or multiple choices. Each button name is like this:

<select id="category" name="category"><option value="" class="header">Category</option>

Through my HTML Form and _POST, I am able to get any 1 field choice result, output is correctly table formatted with correct colors, etc. GREAT!

When I add a 2nd or a 3rd or 4th form choices, I still get ALL the records but NOT Filtered results as I get above (manually). Visitor choices are NOT 1,2,3, in order, but could be any combination thereof like 2,5,7 or 6,7 or 9 etc….

I need the correct PHP handling statement to produce the correct SELECT statement, (POST ARRAY / IGNORE BLANK CHOICE OPTIONS) to see my efforts become reality. ANY help is truly appreciated. After weeks, I am exhausted from reading on my own and not produce correct results – Hundreds of trial and errors, but at least I have given it my best efforts.. I need help…. ! THANK YOU!!!!

  • 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-30T01:17:21+00:00Added an answer on May 30, 2026 at 1:17 am

    Based on your comments I see a few problems:
    You are using OR instead of AND in your query which is your main problem. AND will select the records that have ALL off the specified options; OR selects any records that have any one of the options even if it doesn’t have the rest.

    $query1= "SELECT * FROM $tableName 
    WHERE category= '$category' AND genre='$genre' AND sub_genre= '$sub_genre' 
    LIMIT $start, $limit";
    

    The second thing if I understand correctly is that you want to build the statement dynamically depending on what options are selected?

    Check the value of each dropdown list and if it has a value, add to the WHERE clause

    $query1 = "SELECT * FROM $tableName WHERE [some condition thats always required]";
    if (!empty ($category))
        $query1 .= "AND category = '$category' ";
    if (!empty ($genre))
        $query1 .= "AND genre= '$genre' ";
    [etc...]
    $query1 .= "LIMIT $start, $limit;"
    

    If the only conditions you have in your WHERE clause are the options passed in then you will need to check first if there are any options passed in to determine if you need to add the “WHERE” keyword into your query; and then check which is the first option to be included so you don’t include the “AND” keyword when there is no previous condition to add it to. Or you could cheat and put in an arbitrary condition that is always true, e.g.
    ” WHERE $table_id > 0 ” (assuming you have an id field in your table)

    You also should use numerical ids for the options instead of doing text comparisons on your database which is more inefficient but thats another matter entirely…

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

Sidebar

Related Questions

I have a PHP site with a mySQL database that I'm working on. I'm
I may have have the wrong end of the stick here, but I thought
I have noticed the past couple of weeks that every once in awhile my
I have a report that has a default date range (Start Date -> End
I have been running into this error for the last 3 or 4 weeks
I have a table with weekly data that looks like: userID Site date ------
I created a maven project and I have written for weeks an application and
I have a bug I've been trying to track down for a few weeks
I have been writing C for only a scant few weeks and have not
so after a few weeks, i have got my head around asp.net mvc and

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.