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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:21:49+00:00 2026-05-31T21:21:49+00:00

I have a form with multiple dropdowns consisting of multiple values. I’m trying to

  • 0

I have a form with multiple dropdowns consisting of multiple values.

I’m trying to run a query based on what dropdown has been selected, so if only 1 has been filled out, run the first query, if 2 options have been filled out, run the second and so on and so forth. I’m sure there’s a better way to do this only i’m not too proficient with HTML, any helps greatly appreciated…

<!-- Search query -->

    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <input type="hidden" name="search" value="complete">
        <select name="OPT1">
            <option value="#">Choose Your Fuel Type</option>
            <option value="petrol">Petrol</option>
            <option value="diesel">Diesel</option>
            <option value="lpg">LPG</option>
        </select>

        <select name="OPT2">
            <option value="#">Choose Your Fuel Type</option>
            <option value="petrol">Petrol</option>
            <option value="diesel">Diesel</option>
            <option value="lpg">LPG</option>
        </select>

        <select name="OPT3">
            <option value="#">Choose Your Fuel Type</option>
            <option value="petrol">Petrol</option>
            <option value="diesel">Diesel</option>
            <option value="lpg">LPG</option>
        </select>
        <input type="submit" />
    </form>



    <?php 
        if ($_POST['OPT1'] != '') {     

        echo 'option 1';         
        $pageposts = $wpdb->get_results("SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_value = '".$_POST['OPT1']."' ORDER BY wpostmeta.meta_value DESC", OBJECT); 

        } else if ($_POST['OPT2'] != '') {               

        echo 'option 2';
        $pageposts = $wpdb->get_results("SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_value = '".$_POST['OPT1']."' OR wpostmeta.meta_value = '".$_POST['OPT2']."' ORDER BY wpostmeta.meta_value DESC", OBJECT); 

        } 

        else if ($_POST['OPT3'] != '') {                 

        echo 'option 3';
        $pageposts = $wpdb->get_results("SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_value = '".$_POST['OPT1']."' OR wpostmeta.meta_value = '".$_POST['OPT2']."' OR wpostmeta.meta_value = '".$_POST['OPT3']."' ORDER BY wpostmeta.meta_value DESC", OBJECT); 

        } 


    ?>

Ive got this working…

<?php 
        if ($_POST['OPT2'] == '' && $_POST['OPT3'] == '') {     

        echo 'option 1';         
        $pageposts = $wpdb->get_results("SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_value = '".$_POST['OPT1']."' ORDER BY wpostmeta.meta_value DESC", OBJECT); 

        } else if ($_POST['OPT1'] != '' && $_POST['OPT2'] != '' && $_POST['OPT3'] == '') {               

        echo 'option 2';
        $pageposts = $wpdb->get_results("SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_value = '".$_POST['OPT1']."' OR wpostmeta.meta_value = '".$_POST['OPT2']."' ORDER BY wpostmeta.meta_value DESC", OBJECT); 

        } 

        else if ($_POST['OPT1'] != '' && $_POST['OPT2'] != '' && $_POST['OPT3'] != '') {                 

        echo 'option 3';
        $pageposts = $wpdb->get_results("SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_value = '".$_POST['OPT1']."' OR wpostmeta.meta_value = '".$_POST['OPT2']."' OR wpostmeta.meta_value = '".$_POST['OPT3']."' ORDER BY wpostmeta.meta_value DESC", OBJECT); 

        } 


    ?>

only when pulling my results it pulls really sporadically…

  • 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-31T21:21:50+00:00Added an answer on May 31, 2026 at 9:21 pm

    I think you should remove the # from the option value for the options that are not selected, ie:

    <option value="">Choose Your Fuel Type</option>
    

    then when you test:

    $_POST['OPT1'] != ''
    

    It should work properly.

    If you are trying to check if both option 1 and 2 have values you would use:

    if ($_POST['OPT1'] != '' && $_POST['OPT2'] != '') {
      // run query
    }
    

    edit:
    just reread the last bit you could try something like this to see how many values have been entered in total (not specifically which ones) you could just have a variable called $counter and run each if statement separately (not using elseif) and in each if statement add one to the counter $counter++; at the end you could then see run an if satement to see ifthe value of counter is 0,1,2 or 3.

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

Sidebar

Related Questions

I have a web form that has multiple ListBoxes, TextBoxes, DropDowns. If I put
I have a form that has multiple fields, and for testing purposes is there
i have a form that has a multiple select drop down. a user can
I'm trying to set up a form with multiple dropdown lists, that will allow
I have a form with four dropdowns, each with X amount of values listed;
I have a form that has multiple select drop downs. i.e. Item 1: <select
We have a form that has multiple fields of different data type, including string,
Alrighty then, howdy first off; quick question I have a form that has multiple
I have a table with multiple rows which contain form inputs (checkboxes, text, dropdowns).
I have a form with multiple fields that I'm validating (some with methods added

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.