Forum Moderators: coopster
The database has a field called "category"; the values in "category" are '1','2','3' etc up to 30
An actual record in the database has a category entered as 2
What is the SELECT statement to search for all records that contain a 2 as a category? (records can contain more than one number in their categories, i.e. a record can have categories 2,4,7)
SELECT * FROM mytable WHERE '2' IN CATEGORY
?
From PHPMyAdmin: enter as follows: 'a','b','c'
and so on
All I want are categories that are represented by numbers.
The IN operator is one of those that I teach my school kids everyday when we program in Pascal or Delphi. It's a fairly universal operator to look whether a certain value is found in a set.
Normally I would say:
if (myvalue IN myset) { blah-blah }
and myset would be declared previously as ['a','f','k']
So the whole point of using a set in the MySQL database is that it's MySQL's job to see if the value the user entered is in that set or not.
I checked the MySQL documentation; it gives good examples for SELECT, but it's examples under WHERE are not comprehensive enough.
Have to solve this problem, though, as it's crucial to the entire set of PHP files that I'm writing for a client's website.
I'll have a look at the string functions; still, MySQL is supposed to search the set and return the applicable records.