PHP按名称和姓氏或中间名搜索

I have names like this:

"John Martin Bud" "John Erik"

Ok. Imagine that somebody search for "john bud" OR "bud john".

I want to return "JOHN MARTIN BUD"

But the way I'm doing returns both "JOHN MARTIN BUD" & "JOHN ERIK"

I'm doing this:

$keywords = $_POST['campobusca'];
$keywords=explode(' ',$keywords); 
$string = implode("%' AND name LIKE '%", $keywords);
$sql = "SELECT * FROM names WHERE name LIKE '%$string'";
.
.
.

How can I perform this search?

Thanks

You have a small typo:

$keywords = "john doe";
$keywords=explode(' ',$keywords); 
$string = implode("%' AND name LIKE '%", $keywords);
echo "SELECT * FROM names WHERE name LIKE '%$string'";

will output:

SELECT * FROM names WHERE name LIKE '%john%' AND name LIKE '%doe'

You need to the missing trailing wildcard in the query:

$sql = "SELECT * FROM names WHERE name LIKE '%$string%'";
                                                     ^