Searching in PHP

Hi everyone,

I want to make a search using PHP in a database, and the point is that I only want to take the name of a game, but not the games that contain that word. The code I have:

        $statement = $conexion->prepare("SELECT * FROM listado_precios WHERE pertenece LIKE \"%$pertenece_juego%\"");
        $statement->execute();
        $pertenece = $statement->fetchAll();

This code gives me mostly good results, but when the word is containing in another game (in my case), I receive also another game that I don´t want.

For example if I want to call a game called “Bastion” from the database, the returning games are “Bastion” and “Hope’s Bastion Pack”, when I only want to receive “Bastion”.

Is there a way to deal with this?

Thanks in advice!

Yes, don’t use the wildcards
http://dev.mysql.com/doc/refman/5.7/en/string-comparison-functions.html

With LIKE you can use the following two wildcard characters in the pattern:

% matches any number of characters, even zero characters.

_ matches exactly one character.

2 Likes

Worked!!

Thanks a lot!! :slight_smile:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.