By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,002 Members | 1,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,002 IT Pros & Developers. It's quick & easy.

Dynamic search with checkboxes

P: n/a
Hello everyone.

I'm having a problem with a search I want to make.

It's like this:

The user can choose about 15 checkboxes to be his search pattern.
According to the combination of checkboxes checked, I must do a
different query.

Is it really necessary to make 15 if...else statements and type in a
query for every combination the user may choose?

If anyone knows any easier way to do it, please help me.

Thanks.

Gustavo.

Oct 16 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

GustavoBrust wrote:
Hello everyone.

I'm having a problem with a search I want to make.

It's like this:

The user can choose about 15 checkboxes to be his search pattern.
According to the combination of checkboxes checked, I must do a
different query.

Is it really necessary to make 15 if...else statements and type in a
query for every combination the user may choose?

If anyone knows any easier way to do it, please help me.

Thanks.

Gustavo.
You can post the checkboxes as one array from html, then in use foreach
with one if statement in it.
If you provide us the code it will be easier to determine ...
--------------------------------------------------------------------------
For php/ajax/javascript tutorials and tips, visit me on my blog at
http://www.nurazije.co.nr

Oct 16 '06 #2

P: n/a
In article <11**********************@f16g2000cwb.googlegroups .com>,
nu******@gmail.com says...
>
GustavoBrust wrote:
Hello everyone.

I'm having a problem with a search I want to make.

It's like this:

The user can choose about 15 checkboxes to be his search pattern.
According to the combination of checkboxes checked, I must do a
different query.

Is it really necessary to make 15 if...else statements and type in a
query for every combination the user may choose?

If anyone knows any easier way to do it, please help me.

Thanks.

Gustavo.
You can post the checkboxes as one array from html, then in use foreach
with one if statement in it.
If you provide us the code it will be easier to determine ...
--------------------------------------------------------------------------
For php/ajax/javascript tutorials and tips, visit me on my blog at
http://www.nurazije.co.nr

Depending on the type of query you're building, you might not even need
foreach() ... maybe something like this...

<body>
<form
action="<?php echo $_SERVER['PHP_SELF'] ?>"
method="post"
>
<input type="checkbox" name="id[]" value="1" /><br />
<input type="checkbox" name="id[]" value="2" /><br />
<input type="checkbox" name="id[]" value="3" /><br />
<input type="checkbox" name="id[]" value="4" /><br />
<input type="submit" />
</form>
<pre>
<?php
print_r($_POST);
if(isset($_POST['id']) {
$query =
"SELECT * FROM users WHERE id='" .
implode("' OR id='",$_POST['id']) .
"'" ;
}
// do your query processing
?>
</pre>
</body>

Of course you'd want to do a bit of validation first. And there are
other issues, for example, escaping single quotes, depending on whether
nor not Magic Quotes is enabled on your server.

Oct 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.