0

This is the problem I have. I have a side menu like:

Options A:

A

B

C

Options 1:

1

2

3

Options A and Options 1 are coloumns in a sql table, so If I clicked on A:

whatever.php?OptionA=A

However I want it to be able to multi select, so if I clicked on A, then clicked on B, it would filter the table so that it shows A and B only.

Also, I should be able to select in Options 1 also, so if I clicked on A then 1 it would be:

whatever.php?OptionA=A&Option1=1

The main issue is how can I do it so it can show A and B together?

2 Answers 2

2

Why not use array?

<input type="checkbox" name="option1[]" value="1">
<input type="checkbox" name="option1[]" value="2">
<input type="checkbox" name="option1[]" value="3">

<input type="checkbox" name="option_a[]" value="A">
<input type="checkbox" name="option_a[]" value="B">
<input type="checkbox" name="option_a[]" value="C">

Then...

$box = $_POST['option1'];


foreach ($box as $key => $value)
{
  echo "$key => $value";
}

..etc.

Sign up to request clarification or add additional context in comments.

Comments

0

You will need some jQuery to achieve this task.

First of, you'll need to bind an event to your <select> tags. See the click event with jQuery: Click event

Secondly, you will need to execute a PHP script with the post function of jQuery when the click event occurs. Learn about it here: Post function

Third, now you can execute your PHP script with your post variables received previously.

Your MySql query should look like this (note that you will need to generate your query dynamically):

SELECT * FROM myTable WHERE (OptionsA = 'A' OR OptionsA = 'B') AND (Options1 = '1' OR Options1 = '2')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.