Gossamer Forum
Home : General : Databases and SQL :

Search for cats and links, how to?

Quote Reply
Search for cats and links, how to?
Say i have a table Links with Cars and a table Category with Colors

Say i want to search for all cars that are in cat 1 red, 2 blue, 3 green.

A way to do it, but i hope not the best could be:

1. Select LinksID from CatLinks WHERE CategoryID = 1
If any LinkID => Put all Links in an array
else stop

2. Select LinksID from CatLinks WHERE CategoryID = 2 AND LinkID IN /@array from 1
If any LinkID => Put all Links in an array2
else stop

3. Select LinksID from CatLinks WHERE CategoryID = 3 AND LinkID IN /@array2 from 2
If any LinkID => Put all Links in an array3
else stop

Foreach array3 show cars we are looking for.

If i restrict the seach for three colors this should be ok (anyway we talk about a maximum of 60 Links in around 100 Cats and everyone would be happy to choose 3 or maybe 5 colors, instead clicking a cat like we have it till now.)


But i am shure people who are able to build something wonderful like mysql are able to solve this solution in a better way. So someone has an idea for me, please?
Subject Author Views Date
Post Search for cats and links, how to? Robert 2404 May 3, 2014, 4:37 PM