This has me pulling my hair out!!!
uid-------id--------keyword
1---------72---------fo
2---------72---------bar
3---------72---------is
3---------72---------cool
4---------73---------fo
5---------74---------bar
6---------75---------is
7---------76---------cool
any one know a query to do something like this:
so I have a table with id and keyword as columns now I want to return the id that has attached all the keywords that I have specified (each id can have multiple keywords with each 1d / keyword pair on a new row - ie only 1 keyword per row
I tried this statement:
$SQL = "Select * from keyword where keyword IN ( 'foo', 'bar', 'is', 'cool' )";
but it returns all the ids that have ANY of the the 4 keywords - I want only the ids returned that have attached ALL the 4 keywords... eg going by the table example above I would want returned only id number 72 and none of the others...
Thanks if you can help
--
-Lobos
Professional PHP Framework Services: Concept, Development and Deployment
Watch
GitHub Core
Show your support for Zikula! Sign up at Github account and watch the Core project!
GitHub Modules
- mesteele101 responded to »ERR (3): E_USER_ERROR: Smarty error: [in pagesvar:pagesitem2en line XXX]…« 07:01 AM
- mazdev responded to »Pages 2.5.0 and updating - Page not found« 06:41 AM
- ehdwma created topic »Hide "Register new account" and change template to 3 col« 06:27 AM
- mesteele101 responded to »Zikula 1.3.3 - Selecting a category in Pages not working« 01:29 AM
- mdee created topic »How to implement returnpage ?« 01:00 AM
- nestormateo responded to »Fillters in Clip« 24. May
- damon responded to »Can the Updated Version Check be Turned Off (Z 1.3)« 24. May
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
mysql query
-
- Rank: Expert
- Registered: Dec 02, 2002
- Last visit: Apr 30, 2010
- Posts: 1474
-
**unknown user**
- Rank: Helper
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 877
I don't use mysql for that feature, as I use a simple text file, but I use the following code:
if ((($type == $platform) or ($type == "all")) && (($type1 == $platform1) or ($type1 == "all")) && (($type2 == $platform2) or ($type2 == "all")) && (($type4 == $platform4) or ($type4 == "all")) ) {
echo ......
This checks 4 keywords and returns the results if they match or if the default "all" variable has been set. -
- Rank: Expert
- Registered: Dec 02, 2002
- Last visit: Apr 30, 2010
- Posts: 1474
Ah thanks for your advice, but I cracked it with this SQL:
$query = "
select tID from keyword
where keyword in ( '$cat1', '$cat2', '$cat3', '$cat4' )
group by tID having count(*) = $num
ORDER by tID DESC
";
$num is the amount of "keywords" an item needs to be elligable so if a user only wants to match two keywords they can, if they want to match more they also can.
-Lobos
--
-Lobos
Professional PHP Framework Services: Concept, Development and Deployment
- Moderated by:
- Support
