ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old April 5th, 2005, 10:18 AM
bawaite bawaite is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 84 bawaite User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 50 m 45 sec
Reputation Power: 5
Search results not coming through correctly

I am having a problem with my search tool that is based on the a type of business it is.

right now the user has to choose if the business there adding to a database is:

Dining
Shopping
Entertainment
Services

The user can choose 1 or many of theses items which are all stored in a field as a list.

on the front end when a visitor of the site does a search they had the same list of items as check boxes and none or many of the items.

my problem is in the query statement I have it set-up like this:

Code:
SELECT bID, bName, rName
   FROM business, region
   WHERE 
    bRegion = rID AND
<cfif type neq "">
  (
   <cfloop list="#cookie.type#" index="i" delimiters=",">
    '#i#' IN (bType) <cfif i neq ListgetAt(cookie.type, listlen(cookie.type))> or </cfif>
   </cfloop>
  ) 
   AND
  </cfif>
   0=0

if the user chooses none then it will bring back everything, if they choose multiple it will bring back all the business that have any one of there selections

ex:

if you choose Dining and Shopping it should bring back all the business that are set to Dining, and or Shopping

but right now it is having a problem bring back a business that has multiple types.

Andy suggestion

thank you

Reply With Quote
  #2  
Old April 5th, 2005, 10:30 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,618 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 9 h 44 m 33 sec
Reputation Power: 53
I don't understand why it wouldn't work. Is the database normalized? In other words, do you have a table for the business types, and a table for the businesses, and a table that relates businesses to business types? Or are you trying to store a list of business types along with each business? I would definitely use the first approach.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old April 5th, 2005, 10:47 AM
bawaite bawaite is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 84 bawaite User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 50 m 45 sec
Reputation Power: 5
unfortunately it is only using one table with the type as just on field and all the entries are in the one filed comma delimited. It was set-up before and if possible I rather not re-create the table structure for the site.

Reply With Quote
  #4  
Old April 5th, 2005, 12:05 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,618 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 9 h 44 m 33 sec
Reputation Power: 53
Well then you're going to have a hard time making it work, specifically because if the order of the types is not exactly the same as it is in the database you won't get a match anyway. You can try looking into database functions that let you search within a string (in Oracle substr()), but that is going to be very slow especially if you get a lot of records in the table. I'd strongly recommend normalizing the database correctly, but that's up to you in the end. But be sure you recognize that you're doing this in a very inefficient way.

Reply With Quote
  #5  
Old April 5th, 2005, 12:36 PM
bawaite bawaite is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 84 bawaite User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 50 m 45 sec
Reputation Power: 5
I am aware that there is some problems with the database but it was developed already. But I thought the 'IN' function was used for a list, where it is looking for the word/words in the one field.

Reply With Quote
  #6  
Old April 5th, 2005, 12:57 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,618 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 9 h 44 m 33 sec
Reputation Power: 53
No, you are misunderstanding what IN does. IN allows you to pass a comma-delimited list of values and the database will find any single record that has any ONE of the values you specified. But it has nothing to do with searching a comma-delimited list of values within a single table row and column which is what you are trying to do.

Here is an example:

http://www.1keydata.com/sql/sqlin.html

Reply With Quote
  #7  
Old April 5th, 2005, 01:43 PM
bawaite bawaite is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 84 bawaite User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 50 m 45 sec
Reputation Power: 5
Thank you kiteless

I will redevelop the database when we have time fo the time beeing I will awt it up to use the 'LIKE' function. I know it isn't the best option but it will work

Reply With Quote
  #8  
Old April 5th, 2005, 02:01 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,618 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 9 h 44 m 33 sec
Reputation Power: 53
Yes, LIKE should also work for what you need. Again though, if the table gets large this will run very slowly (LIKE is one of the slowest SQL operators).

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Search results out comming throught correctly


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway