I have a database table set up for keywords. columns are -
keywordID | keyword1 | keyword2 | keyword3 | keyword4 | questionID
I want to provide functionality through a website for a user to find a question and edit it. I'm thinking the best way to do this currently is to have the user search for the question by entering keywords. When I use
SELECT * FROM keywords WHERE keyword1="first_search_word"
it works, but when I try the same but
WHERE keyword2="first_search_word"
it doesn't return any, even though they exist. I also tried using OR
(or ||
) but couldn't find anything about that either.
What is keywordID in relation to keyword1?
Anyway, this isn't the right way to approach your problem. It sounds like you wants tags where every question can be associated with multiple tags, right? This is known as a many-to-many relation and will require more than 1 table. You will need:
To look up what questions have a certain tag, first look up the tagId in the tags table. Then do a SELECT questionId from tags_questions where tagId = $tagId
. To do the lookup based on a keyword not a specific tag you can do SELECT questionId FROM tags_questions WHERE tagId IN (SELECT tagId FROM tags WHERE tag LIKE "%{$keyword}%")
.
When I using
SELECT * FROM keywords WHERE keyword1="first_search_word"
it works, but when I try the same but
WHERE keyword2="first_search_word"
it doesn't return any
But you also say
columns are keywordID, keyword1, ky2, ky3, ky4, questionID
So you dont actually have a column called keyword2
so it would not be surprising there are no matches. Unless of course you have mistyped some values in your question - and should that be the case you should rewrite your question