how can I return all users with names that DON'T begin with a letter? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: how can I return all users with names that DON'T begin with a letter? (/showthread.php?tid=10237) |
how can I return all users with names that DON'T begin with a letter? - El Forum - 07-23-2008 [eluser]got 2 doodle[/eluser] The title says it all, I want to return all users that have chosen to have a user name that does not start with a letter. This is used for a series of anchor's to allow selection of all users with names that start with A,B,C... etc.. Each anchor also has a count of the users within that letter group. So in the controller I have A-Z working. Code: for ($i='65'; $i<='90'; $i++) in my model Code: function count_where_bandname_starts_with($letter = NULL){ So what can I do to get all the folks who use wierd names (these are names of musical groups) like 1of_four or 2cool4words or whatever! any help would be much appreciated doodle how can I return all users with names that DON'T begin with a letter? - El Forum - 07-23-2008 [eluser]jcopling[/eluser] well, there does not appear to be anything in the DB Active Record class to provide you with anything like does_not_start_with, however you can achieve the same thing by using the standard where function like this: Code: function count_where_bandname_starts_with($letter = NULL){ Hope that helps. how can I return all users with names that DON'T begin with a letter? - El Forum - 07-23-2008 [eluser]got 2 doodle[/eluser] Ya thanks, I saw the NOT LIKE syntax, I have achieved the desired result with this code In a model file Code: function count_where_bandname_starts_num(){ So this returns everthing that doesn't fit in the other user groupings (which is what I want). But I wonder if my hack style is missing a key feature in mysql or php or CI? Anything like matching for [A-Z] ?? like a regex Thanks, doodle how can I return all users with names that DON'T begin with a letter? - El Forum - 07-23-2008 [eluser]jcopling[/eluser] Using my example again you could do something like this to only match Alpha characters at the beginning of the field: Code: $query = $this->db->where("username LIKE '[a-z]%'"); or alternatively to select something NOT in range: Code: $query = $this->db->where("username LIKE '[^a-z]%'"); how can I return all users with names that DON'T begin with a letter? - El Forum - 07-23-2008 [eluser]got 2 doodle[/eluser] OK I tried and tried and tweaked and tweaked and then a new approach Code: //This doesn't work This returns the number of bands that start with [0-9] Code: function count_where_bandname_starts_num(){ This returns the data from the table Code: function get_only_number_bands($num,$offset){ So this seems to work fine, but I would be interested in a cleaner approach. I tried some REGEXP stuff in my mySQL queries but nothing worked, it could also have something to do with my version of mySQL. doodle how can I return all users with names that DON'T begin with a letter? - El Forum - 07-23-2008 [eluser]Aea[/eluser] Sub String? I don't know how to do it in active record since it's too weak for anything but the most basic queries. |