SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Searching my 1 table database
-
Sep 6, 2001, 12:36 #1
- Join Date
- Jan 2001
- Location
- Near a computer
- Posts
- 782
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Searching my 1 table database
Sorry for the following non-normalised database, but i am a little desperate so this is the easiest way.
1 db- 1tbl
Now I want to search my entire db on $searchword
why doesn't the following sql-query work:
$sql = "SELECT * FROM tbl WHERE name LIKE '%$searchword%' AND city LIKE '%$searchword%' ORDER BY name OR city DESC LIMIT 0, 25";
Grtz
-
Sep 6, 2001, 13:41 #2
- Join Date
- Aug 2001
- Location
- Kent, Ohio
- Posts
- 367
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What happens when you run this through? Does it just give you an empty set result?
Make sure it's not searching for "%$searchword%" and is actually parsing the variable.. To check, you can alter the string to
$sql = "SELECT * FROM tbl WHERE name LIKE '%".$searchword."%' AND city LIKE '%".$searchword."%' ORDER BY name OR city DESC LIMIT 0, 25";
Otherwise I'm not really sure. Have you tried to run the query while logged into mysql? Was it successful?
-
Sep 6, 2001, 13:53 #3
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
BTW what error are you getting? I think its because of your ORDER BY clause, you can't use OR in it. Try
Code:$sql = "SELECT * FROM tbl WHERE name LIKE '%".$searchword."%' AND city LIKE '%".$searchword."%' ORDER BY name, city DESC LIMIT 0, 25";
Code:$sql = "SELECT * FROM tbl WHERE name LIKE '%".$searchword."%' OR city LIKE '%".$searchword."%' ORDER BY name, city DESC LIMIT 0, 25";
Please don't PM me with questions.
Use the forums, that is what they are here for.
Bookmarks