Compare two text values

Hey again! ;D

Let’s say I have a text value, for example “Peter” and a list of values in database, and one of those is “Pet”.
I want to run a compare function, but I want to find exact same values from database, which is not followed by additional characters in a word.
For example, in a word “Peter” should not be found “Pet”, but in word “Pet Dog” should be found the “Pet” from the database.
So if a word is “Petxyz” it should ignore it. Same if the word have some characters before it: “xyzPet” should not be found. Any suggestions, as I’m pretty stuck with this.

Thanks!

what have you tried so far?

[php]$base_username = check_username($author);

            if ($base_username)
                $usernameData['nickname'] .= (strlen($usernameData['nickname']) > 0 ? : '') . 'This is registered user of our community!';[/php]

And here’s the function:

[php]function check_username($nickname){
global $con;

$stmt = $con->prepare('SELECT * FROM base_usernames WHERE username = :nickname');
$stmt->execute(array('nickname' => $nickname));
$row = $stmt->fetch();

return $row;

}[/php]

Look at a Sql statement with a like clause

Thanks for your quick answer!

Note that I’m not comparing two values from database, I’m comparing one value (a large list of usernames, inside $usernames, with rows from a database.
I’m not sure if a “like clause” can help me here, or I’m wrong?
So, “%Pet%” shouldn’t be fond in this comparison, even though i have a “Pet” in my database.

Trying to understand.

So let’s say ‘Pet’, ‘Peter’, ‘Pet Project’ are in the database.
You are searching for ‘Pet’. ‘Pet Project’ should be the only one found?

In my database i have entry “Pet”.
In $usernames i have “Peter”, and when I compare those two, I shouldn’t get a match.
On the other hand, if I have “Pet something” in $usernames i should get a match with a database if possible.

So anything in $usernames like this %Pet% should get a mach with “Pet” from database, but -> Pet % (with a space between) should get me a mach, or % Pet should get me mach.

Sorry for misunderstanding, English is not my native language, and it’s kinda hard for me to explain what exactly I’m trying to do :slight_smile:

should get a mach with "Pet" from database, but -> Pet % (with a space between) should get me a mach, or % Pet should get me mach.
this

My mistake, sorry, let me correct that sentense:

So anything in $usernames like this %Pet% shouldn’t get a mach with “Pet” from database, but -> Pet % (with a space between) should get me a mach, or % Pet should get me mach.

That’s what I understood. Have you tried that?

LIKE ‘% :username %’

Sponsor our Newsletter | Privacy Policy | Terms of Service