I have a list of names in my database and I have to find the id of the name that I pass in the url.
My problem is that the names I pass in the url will not have a space in them while the saved record will in the database. When I search the database I get no records found.
e.g database record is "My Name" while what I will be passing in the url and searching with is "myname"
if(isset($_GET["name"])) $name = $_GET["name"];
SELECT id
FROM table
WHERE name Like '%$name%'
Thanks for any help.
// id don't know the exact syntax, but this is what you are searching for I guess:
// replace spaces with nothin temporarily, then check equal (=) not like (%%) if name is exactly the same (except the spaces)
SELECT id, REPLACE(name, ' ', '') AS tmp FROM table WHERE tmp='%$name%'
Obviously not the right way to store or search for, but if you must, try replacing the spaces with blanks like this:
SELECT id
FROM table
WHERE REPLACE(`name`,' ','') LIKE '%$name%'
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