Search code examples
phpsqlsql-like

LIKE operator isn't working properly


I'm trying to update some values in a database, the main table where I get the value to update have this structure:

http://api.football-data.org/alpha/soccerseasons/403/leagueTable so in the update query I execute this statement:

UPDATE leaguetable SET matchDay = ?, position = ?, teamName = ?, 
playedGames = ?, points = ?, goals = ?, goalsAgainst = ?, 
goalDifference = ?, self = ?, soccerSeason = ?, team = ? WHERE
self LIKE 'http://api.football-data.org/alpha/soccerseasons/403/leagueTable'"

this query is correct but when I try it in the console of PhpMyAdmin it returns 0 rows because the value self have this structure:

http://api.football-data.org/alpha/soccerseasons/403/leagueTable/?matchday=2

What am I doing wrong in the like attribute?

Note: I pass the value http://api.football-data.org/alpha/soccerseasons/403/leagueTable in a variable called $x, in the post the link is just an example for show the layout of the link.


Solution

  • You need to include the wildcard character % for it to work.

    Read more about it here MSDN LIKE

    Specifically about the wildcard character %

    'http://api.football-data.org/alpha/soccerseasons/403/leagueTable%' finds all URL's beginning with the given, including the desired /?matchday=2.

    In your code:

    UPDATE leaguetable 
    SET matchDay = ?, position = ?, teamName = ?, playedGames = ?, points = ?, goals = ?, goalsAgainst = ?, goalDifference = ?, self = ?, soccerSeason = ?, team = ?    
    WHERE self LIKE 'http://api.football-data.org/alpha/soccerseasons/403/leagueTable%'