So I have a form which searches through a list of companies to see if that particular company is registered on the site.
When the company name is three or less characters and I can see it is in the database the results wont show.
For example, if the company's name is "ABB Eutech" and the search is for ABB, then the search returns 0.
However if you search for Eutech then the search returns the result.
Here's the code I'm using:
<?php
$out = '';
if ((isset($_POST['companysearch-name'])) && ($_POST['companysearch-name']==NULL)) {
$out .= '<h3>No matches. Please enter a company name.</h3>';
} else if (isset($_POST['companysearch-name'])) {
$queryString = htmlspecialchars($_POST['companysearch-name'],ENT_QUOTES);
if(strlen($queryString) >0) {
$query = $wpdb->get_results("SELECT DISTINCT (company_name) FROM wp_companies WHERE MATCH (company_name) AGAINST ('$queryString')");
$searchStr = "%" . $queryString . "%";
$searchStr = str_replace(" ","%",$searchStr);
$numresults = count($query);
if($query) {
$out .= '<div><ul>';
foreach($query as $result):
$out .= '<li>'.$result->company_name.'</li>';
endforeach;
$out .= '</ul></div>';
$out .= "<p>Is your company on this list? If YES, your company already has the scheme in place and you can setup a donation right now.</p>";
$out .= '<a class="button" href="/donate/"><span>Start Giving</span><b></b></a>';
} else {
$out .= '<h3>No matches found.</h3>';
$out .= "<p>Can't find your employer? They may have only just signed up - <a href='/contact-us/'>contact us</a> and we'll check it out for you.</p>";
}
}
}
?>
Any help greatly received! ...Be gentle, it's my first time.
where company_name LIKE %$queryString%but probably it will be slower