El Chupacodra Posted December 1, 2011 Share Posted December 1, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/252246-search-checkbox-noob-problem/ Share on other sites More sharing options...
blacknight Posted December 2, 2011 Share Posted December 2, 2011 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."'"; Quote Link to comment https://forums.phpfreaks.com/topic/252246-search-checkbox-noob-problem/#findComment-1293351 Share on other sites More sharing options...
El Chupacodra Posted December 2, 2011 Author Share Posted December 2, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/252246-search-checkbox-noob-problem/#findComment-1293484 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.