Help with a SQL query.. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Help with a SQL query.. (/showthread.php?tid=20741) Pages:
1
2
|
Help with a SQL query.. - El Forum - 07-20-2009 [eluser]Zack Kitzmiller[/eluser] Here what I need to do. Select some information for a location of a store, where certain options are true. For example, all locations within 5 miles of 61108 where UPS shipping is offered. I have a geocoded Zip Code Library, so i've got an array of locations close to the zipcode I need. And here in the code in my model: Code: function advanced_search($zip_codes, $options) { The loops are running as expected, by results are not as expected. any SQL ninja can help? Help with a SQL query.. - El Forum - 07-20-2009 [eluser]Zack Kitzmiller[/eluser] Code: SELECT * that is the output I'm getting, is there anyway to add parenthesis to what active record is generating to I can fix this, or am I gonna have to write the sql by hand? the expected output would be: Code: SELECT * Help with a SQL query.. - El Forum - 07-20-2009 [eluser]Hakkam[/eluser] How about if you print out the $this->db->last_query() ?? [quote author="techneke" date="1248121017"]Here what I need to do. Select some information for a location of a store, where certain options are true. For example, all locations within 5 miles of 61108 where UPS shipping is offered. I have a geocoded Zip Code Library, so i've got an array of locations close to the zipcode I need. And here in the code in my model: Code: function advanced_search($zip_codes, $options) { The loops are running as expected, by results are not as expected. any SQL ninja can help?[/quote] Help with a SQL query.. - El Forum - 07-20-2009 [eluser]Zack Kitzmiller[/eluser] Look Above... Help with a SQL query.. - El Forum - 07-20-2009 [eluser]Hakkam[/eluser] How should the result ? Please write, the expected result and the query result. Help with a SQL query.. - El Forum - 07-20-2009 [eluser]Zack Kitzmiller[/eluser] [quote author="Hakkam" date="1248126127"]How should the result ? Please write, the expected result and the query result.[/quote] Please look above. The request information was posted a while ago. Thank You. Help with a SQL query.. - El Forum - 07-20-2009 [eluser]slowgary[/eluser] All those OR clauses are VERY VERY inefficient. I hope you at least have an index on the store_zip column. I don't think active record will add that for you. You'll probably need to generate the query manually. Help with a SQL query.. - El Forum - 07-20-2009 [eluser]slowgary[/eluser] You can generate the query manually, but still using CodeIgniter. Do this like so: Code: $this->db->query(" How do you determine which numbers to put into your OR clauses? Help with a SQL query.. - El Forum - 07-20-2009 [eluser]Zack Kitzmiller[/eluser] I have a query that runs from a zipcode DB, provides closest locations. Help with a SQL query.. - El Forum - 07-20-2009 [eluser]slowgary[/eluser] If you're trying to get stores within a proximity, couldn't you just do it like this: Code: SELECT * FROM `db_stores` WHERE `UPS` = '1' AND `store_zip` LIKE '90%'; Wouldn't that be more like what you're looking for? Otherwise, some of these OR clauses are going to be looking for results that are in a completely different state. The last 3 digits are likely duplicated and much less important to the general proximity than the first 2 digits. |