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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:52:10+00:00 2026-05-29T03:52:10+00:00

I have spent over a week trying to get this working and I am

  • 0

I have spent over a week trying to get this working and I am stumped. So I have drop down menu with 5 categories, I have a search form next to it where you can enter a keyword to search against a category. I want to have 5 queries which use a keyword to search against each of the categories using php and SQL server. How can I change the query to match the drop down selection? I was thinking passing a variable to php using JavaScript, but I am not the best programmer, and this idea was too much for me. so category one selected will mean the keyword entered into the search form will run query one etc…

Thank you.

Here is my query:

$term = $_POST[‘term’];

                                                    $tsql = "select * from personnel where SURNAME like '%" . $term . "%'";

                                                    $stmt = sqlsrv_query( $conn, $tsql, array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));

                                                    if( $stmt === false)
                                                    {
                                                         echo "Error in query preparation/execution.\n";
                                                         die( print_r( sqlsrv_errors(), true));
                                                    }

                                                        while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC))
                                                    {
                                                             echo 'NUMBER: '.$row['SNUM'];
                                                        echo '<br/> Jobtitle: '.$row['JOBTITLE'];
                                                        echo '<br/> Last Name: '.$row['SURNAME'];
                                                        echo '<br/> Manager: '.$row['MANAGER'];
                                                        echo '<br/> Sex: '.$row['SEX'];
                                                        echo '<br/> Join Date: '.$row['JOINDATE'];
                                                        echo '<br/> Division: '.$row['DIV'];
                                                        echo '<br/> Salary: '.$row['SALARY'];
                                                        echo '<br/> Bonus: '.$row['BONUS'];
                                                        echo '<br/><br/>';
                                                    }

My form:

<form  action="searchBar.php" method="post">
                                                        <input id="searchstyle" type="text" name="term" />
                                                        <input id="searchbutton" type="submit" name="submit" value="Submit" />
                                                    </form>

And the drop down menu:

<form name="myform" id="dropdown" action="dropsearch.php" method="POST">
                                            <select name="dropdownmenu">
                                                <option value="0" selected="selected">Select a category</option>
                                                <option value="Men">Men</option>
                                                <option value="Women">Women</option>
                                                <option value="Youth">Youth</option>
                                                <option value="Accessories">Accessories</option>
                                                <option value="Teamwear">Teamware</option>
                                            </select>
</form>
  • 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-29T03:52:11+00:00Added an answer on May 29, 2026 at 3:52 am

    You will have to create a form first of all with POST as method

    Here is a good example:

    <form name="myform" action="destination.php" method="POST">
    <select name="mydropdown">
    <option value="1">Fresh Milk</option>
    <option value="2">Old Cheese</option>
    <option value="3">Hot Bread</option>
    </select>
    </form>
    

    In your destination.php file you will have to make a switch statement in order to see what value did you pass to your script.

    switch ($_POST['mydropdown']) {
        case 1:
            $query = "first mysql query";
            break;
        case 2:
            $query = "2nd mysql query";
            break;
        case 3:
            $query = "3rd mysql query";
            break;
    }
    

    After that you will have to execute your query:

    $result = mysql_query($query);
    if (!$result) {
        die('Invalid query: ' . mysql_error());
    }
    

    Note that this is a pretty simple way to do that and however you will have to adapt it to your needs.

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

Sidebar

Related Questions

I've spent over a day trying to figure this out, I have looked at
I have spent this afternoon trying to solve this question: How can I check
I just spent a whole week tracking down and whacking memory leaks over the
I am a newbie and have spent over 3 hours trying to find a
I've spent over three hours on this trying to work with the code I've
This is probably simple, but I have spent way too much time trying to
I've spent over a week trying to figure out a way to do a
I have spent multiple hours trying to figure out how to pass multiple parameters
I have spent several hours trying to find a means of writing a cross
I have spent the afternoon trying to wrap my mind around how to translate

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.