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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:12:08+00:00 2026-06-02T21:12:08+00:00

I need your help with my website search functionality. I’m developing a members area

  • 0

I need your help with my website search functionality. I’m developing a members area wherein users can search other registered users based on certain criteria, or combination of criteria.

My problem now is how to build a dynamic mysql query to suit the need of each combination of search criteria, where the number of criteria is variable.

Normally, I can write with a pre-determined set of criteria using

   WHERE param1 = '$param1'
   AND param2 = '$param2'
   AND param3 = '$param3'

How do I solve this problem?

  • 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-02T21:12:09+00:00Added an answer on June 2, 2026 at 9:12 pm

    If the issue is that you don’t know which of the criteria the user will pick, but want to return results for “blank” criteria, you can use the following:

    $criteria_1 = $_POST['criteria_1'];
    $criteria_2 = $_POST['criteria_2'];
    $criteria_3 = $_POST['criteria_3'];
    
    if(!$criteria_1 && !$criteria_2 && !$criteria_1) {
    
         echo "You must select at least one criteria!";
    
    } else {
    
       // Run query mentioned below and return results.       
    
    } 
    

    THe query would then look like:

    SELECT * from mytable
    WHERE
    (criteria1 = '$criteria_1' OR '$criteria_1' = '') AND
    (criteria2 = '$criteria_2' OR '$criteria_2' = '') AND
    (criteria3 = '$criteria_3' OR '$criteria_3' = '')
    

    This will treat any blank (non-selected) parameters as blank and ignore them. Be aware that with the above, if no criteria are given, it will return all results.

    Another way to write the above is:

    SELECT * from mytable
    WHERE
    criteria1 IN ('$criteria_1', '') AND
    criteria2 IN ('$criteria_2', '') AND
    criteria3 IN ('$criteria_3', '')
    

    Again, allowing for no entry at all to return all criteria1 results.

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

Sidebar

Related Questions

Please i need your help. I'm scripting a comment functionality on my website, and
I realy need your help as this is driving me nuts. On my website
I need your help and advice yet again! I'm trying to do a website
really need your help with log-in-with-facebook feature I'm trying to implement on my website.
Please i need your help with my website (testing stage). I have a file
Need your help...... We are trying to expose API's for auction website(asp.net 4.0) using
Need your help to get the max of CAP_PRICE based on certain criteria in
I need your help. Say I have a code inside a for statement similar
I need your help again :) I'm trying to do a plugin with jQuery
I need your help. I'm trying to install php_apc.dll into my php directory. So

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.