If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Help with SQL query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-22-04, 05:02
C++Casey C++Casey is offline
Registered User
 
Join Date: Oct 2004
Posts: 1
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
Reply With Quote
  #2 (permalink)  
Old 10-22-04, 05:30
RBARAER RBARAER is offline
Registered User
 
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 05:34.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On