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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:11:30+00:00 2026-06-12T23:11:30+00:00

I have populated an html page with a table from the database. I want

  • 0

I have populated an html page with a table from the database. I want to add dropdown boxes at the top that can filter out unnecessary data. How would I go about sending this information to the database to make a query so that I can filter out data with multiple variables?

For example, I have 5 categories, A, B, C, D, and E.
I have used PHP code to populate the boxes with the possible values/entries for A, B, C, D, and E. I’ve also added a “NULL entry” in case the user does not want to include this column as part of the filter.

So right now as it stands, for the respective columns we can have:

Apple, always, as, amazing, as, almonds, NULL.
Belly, boosts, bad, NULL.
Candy, can, create, NULL.
Dandy, does, do, don't, NULL.
Elements, exist, NULL.

How would I go about sending the information to the database when the variables are indefinite? They may or may not be set.

I figured I’d start by seeing if the variables were set in the first place by using the isset(), but how would I proceed from there? It seems like a lot of ‘if’ statements. All I need to do is to change the query based on the values of the variables the user enters. But I don’t see an easy way of doing that.

I’ll simply be adding “WHERE A = this AND B = that AND C = thisthat AND ..” to the end of the query but what if one or more or all of those entries are null?

Thanks a lot for any help.

  • 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-12T23:11:31+00:00Added an answer on June 12, 2026 at 11:11 pm

    You can easily construct your WHERE query as follows

    $where = array();
    
    if ($A != '')
    { 
        $where[] = 'A = "' . $A . '"';
    }
    
    if ($B != '')
    { 
        $where[] = 'B = "' . $B . '"';
    }
    
    if ($C != '')
    { 
        $where[] = 'C = "' . $C . '"';
    }
    
    if ($D != '')
    { 
        $where[] = 'D = "' . $D . '"';
    }
    
    if ($E != '')
    { 
        $where[] = 'E = "' . $E . '"';
    }
    
    // Now get the $where
    $final_where = '';
    if (count($where) > 0)
    {
        $final_where = implode(' AND ', $where);
    }
    
    // $final_where will contain
    // A = 'ab' AND B = 'cd' etc.
    

    NOTE Please make sure to sanitize your input. So for instance you need to add a check for $A that it contains the values that you expect it to contain. Anything else must be discarded. You can use the in_array for instance like so:

    $a_array = array('first value', 'second value', 'third value');
    if (in_array($A, $a_array))
    {
        // Valid choice - we can use it
    }
    else 
    {
        // Not valid set $A to null
        $A = '';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a html table in my page that I populate with items from
I want to create a HTML page that will have a table that will
I have a JSP page that queries a MySQL database, I want to send
So, here's the deal. I have an html table that I want to populate.
I have a table populated with data from the database, where each row has
I have a master page that gets all its images from a table on
I have a page ' foo.html ' that populates a table via AJAX 'ajax.html?options=option1'
I have populated an array with a few html image tags that I have
I have created a populated dropdown list in HTML. When the two dropdowns have
I have a table in HTML. The contents of this table are dynamically populated.

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.