I'm not sure if this is the correct function in using mysql but I was wondering if someone can help me with this problem I'm having
Ex:
I have mysql with these values
id name
1 house_home
2 movie_film
3 restaurant_food
So if I'm trying to find movie
, it should get the value movie_film.
Is strpos function the right function for this case? Or is there another way?
$string = 'movie';
$query = $db->prepare("SELECT * FROM values WHERE name = ?";
$query->execute(array($string));
while($row = $query->fetch(PDO::FETCH_ASSOC)){
echo $row['name']; //this should output movie_film
}
Thanks for help in advance!
Using strpos you will get the position of that string and then trim the length you want
Use LOCATE('substring', 'mainstring')
function
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_locate
You can use the LIKE
'operator' in SQL.
SELECT * FROM values WHERE name LIKE '%?%'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With