SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: Single or multible word search!
-
Jul 8, 2001, 09:53 #1
- Join Date
- Feb 2001
- Location
- Norway
- Posts
- 224
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Single or multible word search!
Hi,
I hope that someone can help me with this code. I am trying to search for some of the words in the database.
Eks:
The exact name is: "XT 600E"
I would like to search for just: "xt" or "xt600"
CODE
Search page:
Model: <input type=\"text\" name="modelsearch" value="">
Result page:
if ($modelsearch == "")
{
$modelsearch = 0;
}
$querystring = "SELECT * FROM homes WHERE ";
$querystring = $querystring."(model >= '$modelsearch')";
elseif ($key == "modelsearch")
{
//do not do anything further -- already handled
}
I know that my code is wrong but it works with numbers
I did visit the php.net site and read something about arreys, but I don't understand how to use them.
Thanks!!!Last edited by Shantra; Jul 8, 2001 at 10:07.
-
Jul 8, 2001, 10:24 #2
$query_string = "select attribute from tbl_name where attribute='xt' || attribute ='XT 600E' || attribute='xt600'":
-
Jul 8, 2001, 10:42 #3
- Join Date
- Feb 2001
- Location
- Norway
- Posts
- 224
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally posted by Ckeren
$query_string = "select attribute from tbl_name where attribute='xt' || attribute ='XT 600E' || attribute='xt600'":
It could be ANY word/words.
Thanks
-
Jul 8, 2001, 11:09 #4
- Join Date
- Aug 1999
- Location
- East Lansing, MI USA
- Posts
- 12,937
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
First of all you have to understand something.
For a computer to know that xt600 means XT 600E you have to program that in.
So you'd write a script that checks to see if the first two characters are letters, then you'd separate them into a new variable, then you check and see if the last 3 are numbers, so on and so forth.
Thats before you even query the database.
As for the rest of the search
Where Field like '%xt%'
will return all rows with xt in it, regardless if it is xt600, or next
% is the SQL wildcard figure and can be used with like statements to search a part of a field instead of the whole field.Chris Beasley - I publish content and ecommerce sites.
Featured Article: Free Comprehensive SEO Guide
My Guide to Building a Successful Website
My Blog|My Webmaster Forums
-
Jul 8, 2001, 11:53 #5
- Join Date
- Feb 2001
- Location
- Norway
- Posts
- 224
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Does this work?
Result page:
if ($modelsearch == "")
{
$modelsearch = 0;
}
$querystring = "SELECT * FROM homes WHERE ";
$querystring = %$querystring%."(model >= '$modelsearch')";
elseif ($key == "modelsearch")
{
//do not do anything further -- already handled
}
-
Jul 8, 2001, 15:30 #6
- Join Date
- Jan 2001
- Location
- California
- Posts
- 342
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
more like:
PHP Code:
if ($modelsearch == "")
{
$modelsearch = 0;
}
$querystring = " SELECT * FROM homes WHERE model='%$modelsearch%' ";
elseif ($key == "modelsearch")
{
//do not do anything further -- already handled
}
This will go in and get all the rows WHERE the column "model" has the text "$modelsearch" in it at all.
Also, your if/then/else structure is incorrect.
Probably need something more like:
PHP Code:if ($modelsearch) {
$querystring = " SELECT * FROM homes WHERE model='%$modelsearch%' ";
//execute sql statement and process results here
} else {
//they didn't search, do normal stuff
}
-Jeff Minard | jrm.cc - Battlefield 2 Stats
Bookmarks