Select non-alphabetic characters only
Posted 28 March 2006 - 09:41 PM
Posted 29 March 2006 - 05:19 AM
Posted 29 March 2006 - 12:24 PM
I am trying to write a php script that searches the names of singers and categorizes them by the first letter of the name. E.g. when I click [a] (hyperlink) I want the page to show me all the singers whose name begins with a.
But there are also people who don't have an alphabetic character for the first letter in their name (or their songs). How do I search for them?
So far I have this:
SELECT name FROM singers WHERE name REGEXP '[^a-zA-Z]' ORDER BY name; //selects non-alphabetic singer's names //& SELECT name FROM singers WHERE name REGEXP '^$letter' ORDER BY name; //$letter could be any alphabetic character.Should I just use SELECT name FROM singers WHERE name LIKE '$letter%' ORDER BY name; instead for the second one?
Am I doing this right?
Posted 31 March 2006 - 10:54 PM
So I ended up using this: SELECT name FROM singers WHERE name REGEXP '[^a-zA-Z]' ORDER BY name; //selects non-alphabetic singer's names
and it worked but not how I wanted. It selected the songs that started with brackets () and numbers but it also selected a few song-names that begin with A too! However, only a few A songs were selected from all the A songs. I think I can stick with it but I would prefer it if there was a work-around/fix.
Posted 01 April 2006 - 01:17 AM
SELECT name FROM singers WHERE name REGEXP '^[^a-zA-Z]' ORDER BY nameHere's how you'd anchor it to the beginning. That will return anything that starts with a non-alphabetic character.
Posted 02 April 2006 - 10:04 PM
Just one last question about another issue, is there any point in putting A-Z (in capitals) since mysql seems to select enteries when they don't exactly have the same case as in the database; If I was searching for a word and forgot to use strtolower() to make a name like Elvis to lowercase and compared it to the database that stores all the names in lowercase, then it would still return the Elvis record. In the database it would be 'elvis' but I just searched for 'Elvis' and it still returned with that record. What do you think? is there any point to using A-Z in the regexp? (is there a speed issue involved?)
Posted 02 April 2006 - 10:12 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users