artemisbow Posted May 6, 2006 Share Posted May 6, 2006 Hi, I'm having problems with comparing values stored in database with values from checkbox... ok let me explain :)Several users selects several checkbox in a form whose values are 1, 2, 3 and 4, and is submited to a script that stores the $_POST data in an array called locations[]. Following that, I did[code]$locations = implode("|", $locations)[/code]which gives me $locations = "1|2|3|4". $locations is then stored in a mysql table in the column user_location.Next a visitor comes along, and in a seperate form, containing the same series of checkboxs, but selects 1 and 3, which is imploded and stored as $requiredlocations = 1|3. Now this is where i'm stuck. The above visitor is filling up a search form to search for users who provide services in various locations. I initially thought of[code]$sql = "SELECT * FROM users where user_location LIKE '%".$requiredlocations."%'[/code]but that will only work if the visitor only checked a single checkbox. How should I write the code such that the visitor can search for multiple locations?Will really appreciate any help. Thanks! Quote Link to comment Share on other sites More sharing options...
artemisbow Posted May 6, 2006 Author Share Posted May 6, 2006 Please... I need help! Thanks! Quote Link to comment Share on other sites More sharing options...
artemisbow Posted May 7, 2006 Author Share Posted May 7, 2006 Anyone? Quote Link to comment Share on other sites More sharing options...
artemisbow Posted May 8, 2006 Author Share Posted May 8, 2006 bump^ Quote Link to comment Share on other sites More sharing options...
.josh Posted May 8, 2006 Share Posted May 8, 2006 hi [b]artemisbow[/b]. actually, i'm working on something very similar to this. the way i have gone about it is to setup 3 tables:providers======provider_nameprovider_idservices=====service_nameservice_idmaintable======provider_idservice_idthis is a relational database. what happens is in table providers, you have a list of all providers and they each have their own id.then, you have another table of services. all the available services are listed, and each one has its own id.then you have this 3rd table (maintable) that looks something like this:maintable======provider_id | service_id---------------------------1 | 31 | 41 | 82 | 12 | 32 | 62 | 8...now the idea behind all this is that when the user wants to search for providers based on the services they offer, you can refer to the maintable, and linkie the provider and service names to their id's from the other tables.now, the query involved in making this happen well probably make you wet your pants. well it made me wet mine, anyways :) anyways, the way i have my script setup so far is for example:if you search for a provider by service1,2 and 3 you can have it match any of the 3 or all of the 3. that is, if a provider has any one of the 3 checked services, it will return that provider. Or, you can set it for 'all' and it will only return providers that offer all 3 of the checked services. now, even though the query matches for the conditions above, it actually lists all of the services provided by each returned provider. that is, let's say you have a provider1 and he offers service1, service2, service3, and service4.now let's say you do a search to find all providers that offer service1 and service3. well, regardless of whether you do search for any or search for all, provider1 will be returned, because it offers both service1 and service3. but what will actually be returned is this:provider1 | service1provider1 | service2provider1 | service3provider1 | service4in other words, it returns all services provided by provider1. the reason why i have it do this is because of how i want to actually display the results to the user. I want it to display something like this:[b]provider1[/b] offers the following services: [b][i]service1[/i][/b], service2, [b][i]service3[/i][/b], service4that's my own personal style i guess. the query probably wouldn't be half as complicated if all i wanted to do was return the provider names and that's it. if you go to :[a href=\"http://www.chroniclesofwar.com/providersearch.php\" target=\"_blank\"]http://www.chroniclesofwar.com/providersearch.php[/a]you can see what i have so far. if you want, i can send you my code so far as well as a create table query for each table i have... Quote Link to comment Share on other sites More sharing options...
artemisbow Posted May 9, 2006 Author Share Posted May 9, 2006 Thanks for the reply. I kindda figured it out by letting part of the sql query be generated by PHP depending on how many checkboxes the user ticked; rest of it is same as wat i had described above. :) Quote Link to comment 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.