I have a column where, pretty much, each entry has numbers (specifically #1-4) and spaces (' '). I wanted to make a query that could avoid having to know these numbers and spaces.
$results = $db->query( "SELECT CHS, PIN, DEF FROM MAIN WHERE CHS LIKE '%".$q."%' OR REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(PIN, '1',''),'2',''),'3',''), '4',''),' ','') LIKE '%".$q."%' OR PIN LIKE '%".$q."%'");
The part that I'm worried (read:ashamed) about is:
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(PIN, '1',''),'2',''),'3',''), '4',''),' ','')
Is this a super bad way to code?
PIN
may eg be1abc
. You then check if that value without the number 1 is like the keyword, and then if the whole thing is like the keyword? So basicallyabc LIKE $q OR 1abc LIKE $q
? In that case, why do you even need the first part of this? \$\endgroup\$