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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:25:35+00:00 2026-06-01T21:25:35+00:00

i have a drop down list populated with values from database. What i am

  • 0

i have a drop down list populated with values from database. What i am trying to achieve is assign a select statement to each value.

menu

Populate menu code

<?php
require 'conn.php';

$filter=mysql_query("select distinct fuel_type from car");
while($row = mysql_fetch_array($filter)) {
$options .="<option>" . $row['fuel_type'] . "</option>";

$menu="<form id='filter' name='filter' method='post' action=''>
  <p><label>Filter</label></p>
    <select name='filter' id='filter'>
      " . $options . "
    </select>
</form>";
}
echo $menu;
?>

Now this menu will be used to filter out car listing and will be placed on the sidebar
cars

How can i assign each value from the drop down list a different select statement like;
select * from car where fuel_type = (dropdown list value selected) without having to submit the form.

perhaps something like the following?

    if($_GET["filter"] == 'Petrol'){
$query=mysql_query("select * from car where fuel_type = 'Petrol'");
header("Location: cars.php");
}
  • 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-01T21:25:36+00:00Added an answer on June 1, 2026 at 9:25 pm

    First, when you’re building your option tag, assign the value that you’d like to filter on in the SQL query to the value attribute:

    $options .="<option value='".$row['fuel_type']."'>" . $row['fuel_type'] . "</option>";
    

    Second, assign unique ID’s to your form and your select element. Then assign the form submit action to the select elements onchange event.

    $menu="<form id='filterForm' name='filterForm' method='post' action=''>
      <p><label>Filter</label></p>
        <select name='filter' id='filter' onchange='document.getElementById("filterForm").submit()'>
          " . $options . "
        </select>
    </form>";
    }
    

    Now when you change the select option, the form will be submitted and the option value that is selected will be populated as that value of the select element #filter.

    On the php page that your form posts to, check for the value of the select element with the id #filter to build the query.

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

Sidebar

Related Questions

i have a drop down list which is populated dynamically from database table i.e
Say I have a form that contains a drop-down list populated by values stored
I have a drop-down list with known values. What I'm trying to do is
Basically I have a drop down list which is populated with text and values
I have a list of drop down lists populated form a database(using ASP.NET). These
I'm trying to get the selected value from a drop down list via jQuery.
I currently have a dropdown list being populated with values from a database. I
I have a drop down list that is populated with data in the code
I have about 10 drop down list controls that get populated. Instead of copying/pasting
I have a drop down list where users can select a theme for the

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.