Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Cant get head round this query...
Old 10-11-2006, 12:14 PM Cant get head round this query...
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
I seem to be full of problems today....

Firstly, I have 3 tables [ flats, facilities and hasFacilities (which links the first two with IDs) ]. Flats i think is notreally important here. facilities contains an ID and a name. hasFacilities contains facilityID and flatID linking the first two together from the normalizatio process.

Im creating a search form where checkboxes are shown, one for each of the facilities within that table. The user will select the relevant ones (any number - none to all) and I want to then query the database to return the flats ( the flatID ) which have all the facilities that the user has selected.

I pretty sure this can be done but i just cant get my head around the query that i need to create - whether thats because i dont have the right knowledge i dont know...

Any helps or points in the right direction are appreciated.

Cheers
Stoot

Table Structures:

flats( flatID, title ... etc )

facilities( facilityID, name )

hasFacilities( flatID, facilityID )

Last edited by stoot98; 10-11-2006 at 12:18 PM..
stoot98 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-11-2006, 05:00 PM Re: Cant get head round this query...
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
I'd add a flats_facilities table with one-to-many relationships from flatID, facilityID and userID (or whatever you called your user table).

So if user1 selected facility1 from flat1, then you'd have userID1, facility1, flat1 from that list. When they update their selection, delete everything from the old selections and reinsert the new ones and you're back in business.

There's nothing saying you can't have multiple relationships among tables like that.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 10-11-2006, 09:28 PM Re: Cant get head round this query...
reli4nt's Avatar
Extreme Talker

Posts: 168
Location: New York
Trades: 0
You could start with
PHP Code:
Select `flatIDFROM `hasFacilitiesWHERE 1 
but then you would need a server side language to check throught the list of possible options like
PHP Code:
$sq .= (isset($_POST['checkbox1']))?"OR `facilitiesID` = '1'":""
The user table idea is only if you are trying to save searches which I am not sure that you want to do.
__________________

Please login or register to view this content. Registration is FREE

Designing the world we live in.
Defining the terms we live by.
reli4nt is offline
Reply With Quote
View Public Profile Visit reli4nt's homepage!
 
Old 10-12-2006, 02:53 PM Re: Cant get head round this query...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
If you have your checkboxes all with the same name the selections will be returned by the form as a comma seperated value list.
So you need to parse this list in whatever server side code you use and concatenate it into AND criterias


SELECT fieldlist FROM hasFacilities as H LEFT JOIN flats AS F ON F.id = H.flatID WHERE H.facilitiesid = criteria1 AND H.facilitiesid = criteria2 .... rest of ANDs ...

Not tested BTW
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-12-2006, 05:07 PM Re: Cant get head round this query...
reli4nt's Avatar
Extreme Talker

Posts: 168
Location: New York
Trades: 0
I should have put AND, I missed the italicized all
__________________

Please login or register to view this content. Registration is FREE

Designing the world we live in.
Defining the terms we live by.
reli4nt is offline
Reply With Quote
View Public Profile Visit reli4nt's homepage!
 
Reply     « Reply to Cant get head round this query...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16722 seconds with 12 queries