how to do a "begins with" search?
Please can someone tell me how to make the following into a 'begins with' search, so that "inter" in the input field will bring up 'interest', 'internet', and 'interview'? It needs to be for any string length.
I tried using LIKE, but it didn't like the percentage sign.
$query="SELECT * FROM contacts WHERE (company='$search_company') or
(classification='$search_classification') ORDER BY company ASC";
Thanks.
# 2 Re: how to do a "begins with" search?
LIKE is exactly what you need. You don't state what database engine you're using, but the syntax is generally WHERE company LIKE 'inter%'. How that plays with PHP I'm not sure, but it should be something along these lines:
$search_company = $search_company + "%";
@search_classification = $search_classification + "%";
$query="SELECT * FROM contacts WHERE (company LIKE '$search_company') or
(classification LIKE '$search_classification') ORDER BY company ASC";
Rune