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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:58:11+00:00 2026-06-05T14:58:11+00:00

I have multi field database, some variables are constant, they are selected using a

  • 0

I have multi field database, some variables are constant, they are selected using a drop menu, some variables are free entry. I want to search the database and find count of rows containing a combination of the selected terms, it works for the most part but if I use more than 2 drop menus for selection it seems to stop working: Form search:

<form  action="search2.php" method="post">
<p>
Name: <input type="text" name="term1" style="background-color:#FFFF11">
<br />
<br />

Dept.: &nbsp;<input type="text" name="term4" style="background-color:#FFFF11">
<br />
<br />

Month: <select name="term2" style="width:65px;  color: black;background-color:#FFFF11">
<option value="" style="background-color: #FFFF11;">...</option>
<option value="Jan" style="background-color: #FFFF11;" >Jan</option>
<option value="Feb" style="background-color: #FFFF11;">Feb</option>
<option value="Mar" style="background-color: #FFFF11;">Mar</option>
<option value="Apr" style="background-color: #FFFF11;" >Apr</option>
<option value="May" style="background-color: #FFFF11;">May</option>
<option value="Jun" style="background-color: #FFFF11;">Jun</option>
<option value="Jul" style="background-color: #FFFF11;" >Jul</option>
<option value="Aug" style="background-color: #FFFF11;">Aug</option>
<option value="Sep" style="background-color: #FFFF11;">Sep</option>
<option value="Oct" style="background-color: #FFFF11;" >Oct</option>
<option value="Nov" style="background-color: #FFFF11;">Nov</option>
<option value="Dec" style="background-color: #FFFF11;">Dec</option>
</select>
<br />
<br />
Year: &nbsp;&nbsp;<select name="term3" style="width:65px;  color: black;background-color:#FFFF11">
<option value="" style="background-color: #FFFF11;">...</option>
<option value="2010" style="background-color: #FFFF11;" >2010</option>
<option value="2011" style="background-color: #FFFF11;">2011</option>
<option value="2012" style="background-color: #FFFF11;">2012</option>
</select>
<br />
<br />

</p>

&nbsp;&nbsp;<input class="button" type="submit" name="submit" value="Submit">
</form>

Search Code:

<?php

include "db.inc.php";
$term1 = $_POST['term1'];
$term2 = $_POST['term2'];
$term3 = $_POST['term3'];
$term4 = $_POST['term4'];
$sql ="SELECT * FROM fixes WHERE tech  LIKE '%$term1%' AND date LIKE '%$term2%' AND date LIKE '%$term3%' AND dept LIKE '%$term4%'";


$rs_result = mysql_query ($sql);
$num_rows = mysql_num_rows($rs_result);
$query = mysql_query("SELECT * FROM fixes WHERE tech  LIKE '%$term1%' AND date LIKE '%$term2%' AND date LIKE '%$term3%' AND dept LIKE '%$term4%'"); 
$number=mysql_num_rows($query); 
?>

If I decide to use drop menu for dept, using same format above it stops working, perhpas there is a better way altogether? thanks

  • 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-05T14:58:13+00:00Added an answer on June 5, 2026 at 2:58 pm

    Generally speaking, the quantity of drop-down menus should have no effect on your form or the corresponding SQL query.

    One thing to consider when you try translating your text fields to drop-downs in your above code is that you remember to keep the names unique (i.e. if you copied your <select...>...</select> code from another term, make sure to change the new SELECT’s name to “term4” or whatever it should be.

    Another thing to consider is if you change to drop-downs, meaning your input values are finite and knowable, you should change your SQL to use ...WHERE dept = '$term4'... instead of LIKE; this should make for a speedier query since you have no need of wildcards or partial matching when you know all the possible options.

    And as I commented above, don’t forget to escape your variables when you use them in your query to avoid SQL Injection.

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

Sidebar

Related Questions

I'm stuck with a database which is using multi-field primary keys. I have a
I'm using 'rails3-jquery-autocomplete' gem, but it doesn't have multi column search, but there is
I have a multi-xaml metro app. I want to switch between xaml by button
Scenario: In the database I have a field called Categories which of type string
I have data that I want to pull from a mySQL database and I
We have a common database schema that we use for some tables in our
The scenerio is like this: I have to use multi-field query, which indexed several
We have multi-part install that needs a reboot to continue. We added a RunOnce
I have a multi-array stored in a SESSION I loop through the data in
I have a multi-step order form built in this manner: Step 1: Choose category

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.