Jump to content

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

why wouldent you use a dropdown insted?

or

$id_nums = implode("' OR `nationality` = '", $_POST['natBox']);
$query = "SELECT * FROM user_criteria WHERE (age BETWEEN '".$ageFr."' AND '".$ageTo."') AND  `nationality` = '".$id_nums."'";

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.