How can I select a row in my MySQL DB where the value of a column contains 'XcodeDev' for example?
I tried:
SELECT * FROM Accounts WHERE Username LIKE '$query'
But it only selects a row were the Username value is exactly the same to the query.
What can I do to achieve what I want?
MySQL query string contains using INSTRINSTR(str, substr) function returns the index of the first occurrence of the substring passed in as parameters. Here str is the string passed in as the first argument, and substr is the substring passed in as the second argument.
If you want to select only specific columns, replace the * with the names of the columns, separated by commas. The following statement selects just the name_id, firstname and lastname fields from the master_name table.
Use the %
wildcard, which matches any number of characters.
SELECT * FROM Accounts WHERE Username LIKE '%query%'
This should work:
SELECT * FROM Accounts WHERE Username LIKE '%$query%'
My suggestion would be
$value = $_POST["myfield"];
$Query = Database::Prepare("SELECT * FROM TABLE WHERE MYFIELD LIKE ?");
$Query->Execute(array("%".$value."%"));
SELECT * FROM Accounts WHERE Username LIKE '%$query%'
but it's not suggested. use PDO
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