Danian Posted February 17, 2011 Share Posted February 17, 2011 Hi All, Hope you can help, i have a MySQL string that i want to remove all the spaces in name and postcodes and then uppercase them, before I try to match them in the Database, but spent a couple of hours and tried various ways, but still failing. Please can yo have a look and advise.... SELECT * FROM vwproperty WHERE str_replace(' ', '', strtoupper(surname)) LIKE '% ."strtoupper(str_replace(" ", "", {$_SESSION["Surname"]}))."%' AND str_replace(' ', '', strtoupper(postcode)) LIKE '% ."strtoupper(str_replace(" ", "", {$_SESSION["Postcode"]}))."%'ORDER BY surname Thanks in Advance, D Quote Link to comment https://forums.phpfreaks.com/topic/228034-mysql-with-php-help/ Share on other sites More sharing options...
fenway Posted February 17, 2011 Share Posted February 17, 2011 Failing how? Echo the actual statement. Quote Link to comment https://forums.phpfreaks.com/topic/228034-mysql-with-php-help/#findComment-1175856 Share on other sites More sharing options...
BoarderLine Posted February 21, 2011 Share Posted February 21, 2011 Im not the best at this, however will attempt to add some thoughts as it appears no one else is willing to help you here. You have mixed your php in with your mysql statement which I cant see working. You need to first set the PHP values outside the MySql statement. eg. [code=php:0] $surname = "%".strtoupper(str_replace(" ", "", $_SESSION["Surname"]))."%"; $postcode = "%".strtoupper(str_replace(" ", "", $_SESSION["Postcode"]))."%"; [/code] And then call them in your MySql like this: SELECT '$something' FROM '$surname' WHERE etc. And to get the upper and lower case of database fields in Mysql you need to use lcase() and ucase() functions, although I don't believe the match here is case sensitive, nor should you require a str_replace for spaces if you are using wildcards. Quote Link to comment https://forums.phpfreaks.com/topic/228034-mysql-with-php-help/#findComment-1177496 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.