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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:49:34+00:00 2026-06-14T14:49:34+00:00

I have made a filter using a form with drop down lists. The filter

  • 0

I have made a filter using a form with drop down lists. The filter is used to filter results from a mySQL database. The form is processed on the same page as the results. I want to make it so that the filter drop down lists retain the filter parameters once the results have been filtered.

I have done this in the past by using a session, however that was when I used another page to process the query. I have tried to apply this same theory but it isn’t working. I have searched this site as well as Google and I have only found answers related to a separate page for processing.

Currently the code that I have will only pre-populate the form after it has been submitted twice. The first time it is submitted it shows the default setting of “Select…”

Here are the relevant sections of my code:

session_start();
if(isset($_SESSION['submitted_filter_values']))
{
extract($_SESSION['submitted_filter_values']);
}

<form action="#filter" method="post" name="filter">
<table>

<tr>
<td>
<select name="prefix">
<option value="">Select...</option>
<option <?php if(isset($prefix) && $prefix == "PDM"){echo "selected=\"selected\"";} ?> value="PDM">PDM</option>
<option <?php if(isset($prefix) && $prefix == "TB"){echo "selected=\"selected\"";} ?> value="TB">TB</option>
<option <?php if(isset($prefix) && $prefix == "JNL"){echo "selected=\"selected\"";} ?> value="JNL">JNL</option>
</select>
</td>
</tr>

<tr align="center">
<td colspan="2"><input type="submit" class="btn_150x30" name="submit" value="Filter Results"></td>
</tr>

</table>
</form>

$_SESSION['submitted_filter_values'] = $_REQUEST;

I have tried placing the session variable in different locations but that didn’t work. I thought maybe refreshing the page would work but then I figured it would effectively remove the filter like it does when I submit the form twice. Interesting point to note is that is it very consistent in that it works literally every second time I submit it, so every odd submit it does not populate and every even submit it populates.

  • 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-14T14:49:36+00:00Added an answer on June 14, 2026 at 2:49 pm

    After realizing that the session wasn’t a good idea for my application, because it is only being used on one page and not throughout the site, I have taken a fresh approach to the problem.

    At the top of my filter I have this for each option:

    if(isset($_POST['prefix']))
        {
        $prefix = $_POST['prefix'];
        }
    

    Then in my drop down list, I have this for each option:

    <option <?php if(isset($prefix) && $prefix == "PDM"){echo "selected=\"selected\"";} ?> value="PDM">PDM</option>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using preg_match function to filter unwanted characters from a textarea form in
I have made a sample application which constructs a filter graph to capture audio
I have made a code that read data from flash Nand (without filesystem). fd
I have made a website using( Asp.net, c# ) and its content in English
I have made a String[] array by using String.split(.) . I am now trying
I have a custom DirectShow filter created by extending the ezrgb24 filter from the
I have many instances of the same type of problem using jQuery. Probably because
I am new to django and have made a method:GET form with checkboxes/text boxes
I am new to zend framework. I have used zend form and decorators to
I have successfully made my 4 CRUD actions restful by using mapResources in 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.