Jump to content

[SOLVED] Using REPLACE to sort alphabetically ignoring punctuation?


blakekr

Recommended Posts

Someone very good at mysql helped me create an ORDER BY statement that would allow my program to display item names alphabetically without putting items in quotes at the beginning. Works a charm, except I can't figure out how to craft a REPLACE statement that ignores more than one type of punctuation ... e.g. I need to ignore both double quotes and single quotes at least.

 

Here is my original statement -- works great:

 

        if ($SortBy == 1) { // Either explicit or default set above
             $orderBy = "category , REPLACE(`prod_name`,'\"', '') ";

 

 

Here is my attempt to ignore both double and single quotes, doesn't work as expected:

 

        if ($SortBy == 1) { // Either explicit or default set above
             $orderBy = "category , REPLACE(REPLACE('prod_name','\\\"',''),'\'','') ";

 

Any advice appreciated!

 

Thanks,

Blake

Link to comment
Share on other sites

Hi,

in inner REPLACE you are searching for \" instead of ".

This code should work:

if ($SortBy == 1) { // Either explicit or default set above
             $orderBy = "category , REPLACE(REPLACE('prod_name','"',''),'\'','') ";

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.