SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    where statements with wildcards for field names

    I am trying to create a dynamic Web site with minimum pages. I am coding in cold fusion.

    I have two tables: Subjects, Products

    I am creating a dynamic navigation system that pulls all of the subjects and their unique ID's.

    <CFOUTPUT QUERY="Query1">
    <a href="/tile_murals_subject.cfm?SubjectID=#SubjectID#">#Subject#</a>
    </CFOUTPUT>

    For the product pages, I am using the table Products.

    I have three fields titled "Subject1, Subject2, Subject3" that is linked to the Subjects table.

    How can I create a wildcard in the where statement for a field name?

    I bascially want to say, show me the results of products where the value for SubjectID appears in either of the following fields: Subject1 or Subject2 or Subject3 of a product record.

    <CFQUERY datasource="art_collection" name="Query1">
    Select * From Products
    Where Subject1 or Subject2 or Subject3 ='#SubjectID#'

    I know I need to somehow transform the field name into a wildcard Subject_
    </CFQUERY>

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    695
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    You shouldnt have repeating columns (Subject1, Subject2, Subject3). When there is a one to many relation between products and subjects, that should be stored in a separate table.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •