Fumio
Fumio

Reputation: 13

using LIKE in Sql in PHP web page

I have the code below to search for the text 'english' anywhere in the field language. I've tried formatting the code from SQL into a web PHP page but it doesn't display any information. When I run the sql version select language from media where language like '%english%' it works.

$result = mysql_query("SELECT `language` FROM `media` WHERE `language` LIKE \'%english%\'");

while ($row = mysql_fetch_array($result)) {
echo $row[''];
echo ' ' , $row['language'];
echo '<br />';
}

Upvotes: 0

Views: 30

Answers (2)

hichris123
hichris123

Reputation: 10223

You don't need to escape the ''s. It should just work. So try this:

$result = mysql_query("SELECT `language` FROM `media` WHERE `language` LIKE '%english%'");

Upvotes: 1

John Conde
John Conde

Reputation: 219794

Don't escape the single quotes around your search term.

$result = mysql_query("SELECT `language` FROM `media` WHERE `language` LIKE '%english%'");

Upvotes: 1

Related Questions