If I wanted to return any row that contained the number 1, how would I do that without returning everything with a 1 in it (whether it was 1 or 112) I want it to only return rows with a 1 in it... I can't figure it out.column wrote:1 23 156 87 3
Finding a word in a database
Moderator: General Moderators
Finding a word in a database
Alright... in my database for my directory, I have a column named categories... in that column there is a list of numbers (category ids) in the following format...
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
well I tried
No luck. I don't think LIKE is what I need... I'm starting to think I will need to reformat the column to be like this..
But that will be a lot of work... I don't really want to do that... anybody know how I can get this accomplished?
edit: Seems to be working
Code: Select all
SELECT * FROM table WHERE categories LIKE '%1'Code: Select all
'1' '12' '2345' '123'edit:
Code: Select all
SELECT *
FROM directory
WHERE `directory_categories` = '10'
OR `directory_categories` LIKE "%10 "
OR `directory_categories` LIKE " 10%"
OR `directory_categories` LIKE "% 10 %"If you're using mysql you can use full-text search.
Code: Select all
SELECT * FROM directory WHERE MATCH (directory_id) AGAINST ('10')Where the row is 1?
Where the row contains 1?
where the row contains 1 but is not 1?
Code: Select all
where `row` = 1Code: Select all
where `row` like '%1%'Code: Select all
where `row` like '%1%' and `row` <> 1Nope... still nobody understands what I am trying to do... let me start over:
directory:Now I want to find every row that contains "1" in the category list, but everything I try returns anything with a 1 in it whether it's 1 or 123
I would only want it to return row # 1, 2, and 4 in this example.
EDIT:
Like I said... seems to be working, but I don't know if it's the most efficient way.
directory:
Code: Select all
id name description phone_number category
1 Sierra Somethting 5308778123 1 2 564 124
2 comp something 5308778612 10 1 567
3 som somethin 1234567898 12 36
4 1q2 somdthasdf 9876543218 1
5 as;lk soemthin 2342345223 23 25 65 321I would only want it to return row # 1, 2, and 4 in this example.
EDIT:
Like I said...
Code: Select all
SELECT * FROM directory WHERE `directory_categories` = '72' OR `directory_categories` LIKE '72 ' OR `directory_categories` LIKE ' 72' OR `directory_categories` LIKE '% 72 %'I'm sorry... that sounds helpful, but I don't understand... can you explain a little better?
I got it working, but not as well as I had hoped... the directory isn't very big, so the time it takes to find them isn't very long right now, but I bet if there were more rows, it would take foreve the way I'm doing it (the way I said above)
Here is the directory in action: http://www.paradisedirect.com/directory.php
I got it working, but not as well as I had hoped... the directory isn't very big, so the time it takes to find them isn't very long right now, but I bet if there were more rows, it would take foreve the way I'm doing it (the way I said above)
Here is the directory in action: http://www.paradisedirect.com/directory.php