Searching by Category and Zip code |
[eluser]derekmichaeljohnson[/eluser]
I have a search form with 2 fields: category (dropdown) and zip code. If they click "Find" without entering anything, they get all "users" currently in DB. If they select a category, they get all "user" records assigned to that category. Pretty simple stuff. Here's the code so far: Code: // Join users and cats And now the part where I'm stuck. I'm using a Zip Code class which returns an array containing zip codes within 20 miles (default) of the entered zip code. Example result array: Code: array I tried this (see below), but it gives me results that EITHER match the selected cat OR the zip codes in the array... which is no good... Code: $zip = $this->input->post('zip');
[eluser]derekmichaeljohnson[/eluser]
[quote author="Jbeasley6651" date="1247905504"]don't use or where in, use where in again...[/quote] But if I use WHERE IN in the foreach loop, I'll end up with: Code: $this->db->where_in('cat','2'); Code: $this->db->where_in('cat','2');
[eluser]Nicholai[/eluser]
Couldn't you do something like this? Lose the foreach loop and use a where_in statement with the zip code field of your array. My syntax may be off but the logic feels correct. I still have trouble with the right syntax to pull one field out of an array. Code: $this->db->select('users.*, users_cats.cat_id, cats.name AS cat');
[eluser]derekmichaeljohnson[/eluser]
[quote author="narayanis" date="1248049101"] Code: if($zip) Won't calling $zips['zip_field'] return just ONE of the zip codes? Also, the problem is that the returned zip codes are the KEYS of the array, not the VALUES.
[eluser]Nicholai[/eluser]
No, it would return all of the zip codes, separated by commas. The user guide shows here what happens when you send an array into a where_in(): Code: $names = array('Frank', 'Todd', 'James'); If the ZIPs are keys instead of values, use the PHP function array_keys(): Code: if($zip) |
Welcome Guest, Not a member yet? Register Sign In |