Jump to content

Search Checkbox Noob Problem


El Chupacodra

Recommended Posts

Hi gang, new to posting but I've read the forum on and off.

 

I'm coding a small community and will have a lot of questions for you over time.

The first one is about a search function.

 

We'll have users of different nationalities and languages and you will be able to search, only I was thinking there could be a better way.

They'll enter those posts through a dropdown list and when you search it you will use checkboxes.

I just don't see the results I want when I pick the array for info.

 

Like I have this right now as the form (which is sent to the php page itself as POST):

Nationality: <br />

<input type="checkbox"" name="natBox[]" size="30" value="all"/> All<br />

<input type="checkbox"" name="natBox[]" size="30" value="weuro"/> W Europe<br />

<input type="checkbox"" name="natBox[]" size="30" value="eeuro"/> E Europe<br />

<input type="checkbox"" name="natBox[]" size="30" value="wafrica"/> W Africa<br />

 

And the thing I was doing was to check the boxes with if (isset) and then make the query longer and longer, butI figure there could be a smarter way.

Like if I was going to enter 200 countries I can't really check for all can I?

 

After the check (now deleted) it sets the query to this:

 

$query = "SELECT * FROM user_criteria WHERE (age BETWEEN '$ageFr' AND '$ageTo') AND nationality='$nationality'";

 

...and the part I don't have now is to pick the array natBox and add every value so @nationality becomes for instance weuro OR wafrica etc.

 

Got a more elegant approach?

Link to comment
https://forums.phpfreaks.com/topic/252246-search-checkbox-noob-problem/
Share on other sites

Hello and thanks for helping.

I need checkboxes for the user to select multiple criteria more easily.

Then again I might look at those again.

The implode idea is good , I think I had a version of it at some point.

As you can tell I'm in a very early stage with this.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.