Jump to content

MySql with PHP help


Danian

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.