Edit : my question is not a duplicate of how to highlight search results since i am trying to work with the query and not the query results. I know i could work with the query result and i even tried, but that create other issues with case insentive and accentuation. So, if there is a way to do it with mysql (which is my question), kind like this Mysql : Select query with like but with PDO prepared statement ... Please, keep this question open !
I have this kind of data in my database "mydb" :
id | name
---------
1 | abcdef
2 | bcdefg
3 | cdefgh
4 | defghi
5 | efghij
I do a PDO prepared query like this one :
$q = "SELECT * FROM `mydb` WHERE name LIKE :search ;";
$res = $cnx->prepare($q);
$res->bindValue(':search', '%'.$_POST['search'].'%');
$res->execute();
In my example, $_POST['search'] = 'defgh'
, so i get those results :
id | name
---------
3 | cdefgh
4 | defghi
I would like to know if there is a way, with mysql and PDO, to inject html code which encompasses the string searched with "LIKE" statement directly in the result ?
So the results would be :
id | name | html
----------------
3 | cdefgh | c<mark>defgh</mark>
4 | defghi | <mark>defgh</mark>i