开发者

Multiple php query string and multiple select options

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

开发者_JS百科

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?


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.


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')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜