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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:56:30+00:00 2026-06-03T03:56:30+00:00

hello i like to code a filter for my search engine. i have some

  • 0

hello i like to code a filter for my search engine. i have some problems with the different select queries. so the main idea is that i have some inputfields with checkboxes like:

inputfield a: [_] filter on/off: [ ]

inputfield b: [_] filter on/off: [ ]

inputfield c: [_] filter on/off: [ ]

to set the query i have named the query for each field:

if ($filter_a == true) {
        $filter_1 =" `a` LIKE '%$input_a%' ";
    }

if ($filter_b == true) {
        $filter_2 =" `b` LIKE '%$input_b%' ";
    }

if ($filter_c == true) {
        $filter_3 =" `c` LIKE '%$input_c%' ";
    }

so in case of an enabled filter the select query should change in a specific way like:

in case of enabled filter_a:

$query = "SELECT `a`, `b`, `c` FROM `table` WHERE $filter_a";

in case of enabled filter_a AND filter_b:

$query = "SELECT `a`, `b`, `c` FROM `table` WHERE $filter_a AND filter_b";

in case of enabled filter_a AND filter_b AND filter_c:

$query = "SELECT `a`, `b`, `c` FROM `table` WHERE $filter_a AND filter_b AND filter_c";

i’m having problems with adding “AND” to the queries. therfor i have integrated a counter that counts how many filters are set:

$counter = 0;
...
if(!empty($_POST['input_a']) && (!empty($_POST['checkbox_filter_1'])) ){
        $filter++;
}
...

if ($counter == 2) {
$and1 = " AND ";
     $query = "SELECT `a`, `b`, `c` FROM `table` WHERE $filter_a $and1 filter_b";
}

so the main problem is permutation. up to this point i have 5 filters what means there are 125 possibilites to compare with.

so my next idea would be to create an array with each query and order them.

so it should look like:

$ordered_query = (
1-> `a` LIKE '%$input_a%',
2-> `b` LIKE '%$input_b%',
3-> `c` LIKE '%$input_c%');

so that i have all queries in one array. the next step should be to order them regarding the filters who are set or not.

so in case of enabling filter_3 and filter_1 it should order the array keys:

$ordered_query = ( 1-> input_a 2-> input_c );

and the query should automaticallyadd AND between them. in case of all enabled filter there have to be 2 AND`s between.

if there is someone who could help me out i really i would appreciate.

thanks a lot.

  • 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-03T03:56:32+00:00Added an answer on June 3, 2026 at 3:56 am

    You should put all conditions in an array and use function implode:

    $conditions = array();
    $conditions[] = " `a` LIKE '%$input_a%' ";
    $conditions[] = " `b` LIKE '%$input_b%' ";
    // ...
    $query = "SELECT ... WHERE ".implode(" AND ", $conditions);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello i would like to code a filter for an search engine on my
I have seen the run_once method in some code like run_once do [:hello, :core,
Say you have a C code like this: #include <stdio.h> int main(){ printf("Hello, world!\n");
If I have some lua code like this: doSomething(function() print(Hello!) end) How can I
Hello I have a code like that : try { // Here I call
I have code like <?php header('Content-Type: text/plain; charset=UTF-8'); echo 'Hello Loréane !'; the e
I have a C++ DLL with code like this: LogMessage( Hello world ); try
I have a string like: hello #this# is #some text string# text text I
Currently I am doing this: I have text that looks like: Hello ${user.name}, this
I have ruby code like this: module Hello class Hi def initialize() puts self.module.name

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.