Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2004
    Posts
    1

    Unanswered: Help with SQL query

    Hi

    I have a database that has a column named "SubCategory". Within the subcategory column there are 3 fields (Banks, Lenders, Realtors)I'm passing an URL parameter and what I'm trying to do is select certain fields only if the SubCategory ='Realtors' and the BankLocation='URL Parameter value"

    So here is the query I have:

    Code:
    SELECT username, company, categories, profile, email
    FROM freelancers_programmers
    WHERE freelancers_programmers.SubCategory = 'Realtor' AND BankLocation = 'colname'
    The 'colname' is a variable whose name is 'colname' has a default value of 1, and a runtime value of $_GET['BankLocation'] and it carries of the value of the selected state when passed

    The problem I'm having is that the query isn't filtering the SubCategory='Realtors'....the search results come back with not only 'Realtors', but 'Banks' and 'Lenders' as well. I only want 'Realtors' whose 'BankLocation' is passed in the search.

    If you need to see a live example visithttp://www.searchbanks.com//realtors.php

    and use the "
    Quick Search by States" section...Florida has the 'Realtor' and 'Alabama' has a lender but if you choose 'Alabama' the lender comes back in the search result....that shouldn't happen because I want to limit the search results on this page to 'Realtors' only for the selected state.

    Thanks for your time and any advice

  2. #2
    Join Date
    Aug 2004
    Location
    France
    Posts
    754
    Hello,

    First of all, I think we should clarify some vocabulary... From your query, it seems to me that :

    "freelancers_programmers" is a table (do you have only one ?),
    within which you have a column (or field) "SubCategory",
    which may have values among 'Banks', 'Lenders', 'Realtors'.

    Is that so ? Because if it is, I don't see any error in your query.

    However, why do you have "freelancers_programmers.SubCategory" and "BankLocation". Both columns belong to the "freelancers_programmers" table, isn't it ? If it is, you could just put "SubCategory". This is just a detail, but I try to understand why it would not work properly.

    Could you please be more precise about your schema ? Don't you have to use other tables ?

    Regards,

    RBARAER

    PS : you put 'Realtors' with 's' everywhere except in your query where you put 'Realtor'... but even if it were an error, then you would have no result at all, not all results... really strange. Are you sure you did put "AND" in your code and not "OR" ? Then it would make sense.
    Last edited by RBARAER; 10-22-04 at 06:34.

Posting Permissions

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