Re: Simple Search Logic Issue...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



revDAVE wrote:

> Newbie question...
> 
> 
> I have a search page with multi lines of search criteria:
> 
> Name
> Topic
> Message
> Etc...
> 
> I'm hoping to get results based on what criteria I type - but I'm not
> getting what I expect. I think it's just getting results where in addition
> to getting search criteria I type - ALSO none of the search fields can be
> blank (not what I hoped) ...
> 
> Like I type just 'c' in the name field and it shows 3 records (other
> search fields filled up) ... But I have many more records with name
> containing 'c'
> 
> Goal: to search for what I type in whatever search fields and not worry
> about whether others are blank or not - like:
> 
> Name contains 'c'
> 
> Charles
> Chuck
> Chuck
> Chas
> 
> Or
> 
> Name contains 'c' and topic contains 'test1'
> 
> Maybe just charles fits this criteria
> 
> ----------
> 
> 
> I made a simple results page,
> 
> ... More code here ... ( DW CS3 )
> 
> $name_list1 = "-1";
> if (isset($_GET['Name'])) {
>   $name_list1 = $_GET['Name'];
> }
> $top_list1 = "-1";
> if (isset($_GET['Topic'])) {
>   $top_list1 = $_GET['Topic'];
> }
> $mess_list1 = "-1";
> if (isset($_GET['Message'])) {
>   $mess_list1 = $_GET['Message'];
> }
> mysql_select_db($database_test1, $test1);
> $query_list1 = sprintf("SELECT * FROM mytable WHERE Name LIKE %s and
> Message LIKE %s and Topic LIKE %s ORDER BY mytable.id desc",
> GetSQLValueString("%" . $name_list1 . "%", "text"),GetSQLValueString("%" .
> $mess_list1 . "%", "text"),GetSQLValueString("%" . $top_list1 . "%",
> "text"));
> 

You do understand how LIKE works? You need to use wildcard characters if you
want to match other than the exact string you pass to it.

For example LIKE 'c' will only match a field that contains just 'c'

LIKE '%c' will match a field starting with 'c' and containing any number of
characters

LIKE '%c%' will match a field containing 'c' anywhere

If you are using that syntax, I'd suggest echoing your query to make sure
that it is as it should be; I'm wondering if you are actually enclosing
string values in single quotes in your query?

As for multiple selection criteria, you need to test whether the passed in
value is set or not, and only include set values in the query.

OT: sprintf syntax is so hard to read :-)

Cheers
-- 
David Robley

Make like a banana and split.
Today is Sweetmorn, the 46th day of Chaos in the YOLD 3175. 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux